时间格式化 Date-formatDate
//日期格式化
export function formatDate(date,fmt){
var o = {
"M+":date.getMonth() + 1,//月份
"D+":date.getDay(),//日
"h+":date.getHours(),//hours
"m+":date.getMinutes(),//分钟
's+':date.getSeconds(),//秒,
}
if(/(y+)/.test(fmt)){
//RegExp.$1 是RegExp的一个属性,指的是与正则表达式匹配的第一个 子匹配(以括号为标志)字符串,以此类推,RegExp.$2,RegExp.$3,..RegExp.$99总共可以有99个匹配
fmt = fmt.replace(RegExp.$1,(date.getFullYear()+'').substr(4 - RegExp.$1.length));
}
for(var k in o){
if(new RegExp("("+k+")").test(fmt)){
fmt = fmt.replace(RegExp.$1,(RegExp.$1.length===1)?(o[k]):(("00"+o[k]).substr((""+o[k]).length)))
}
}
return fmt;
}
调用:
项目中:import {formatDate} from "./formatDate.js"
js中:formate(new Date(),'yyyy-MM-DD hh:mm:ss')
时间格式化 Date-formatDate的更多相关文章
- js时间格式化(yy年MM月dd日 hh:mm)
//时间格式化 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, / ...
- 3种 Springboot 全局时间格式化方式,别再写重复代码了
本文收录在个人博客:www.chengxy-nds.top,技术资料共享,同进步 时间格式化在项目中使用频率是非常高的,当我们的 API 接口返回结果,需要对其中某一个 date 字段属性进行特殊的格 ...
- Java魔法堂:Date与日期时间格式化
一.前言 日期时间的获取.显 ...
- js Date 时间格式化的扩展
js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...
- 【推荐】PHP中格式化时间函数date与gmdate的区别 | 修改PHP的默认时区
PHP中的时间有2个格式化函数:date()和gmdate(),在官方的文档中的描述为: date -- 格式化一个本地时间/日期 gmdate -- 格式化一个 GMT/UTC 日期/时间,返回的是 ...
- date时间格式化
Date方法的扩展 /** * 时间格式化 * @param fmt * @returns {*} * @constructor */ // (new Date()).Format("yyy ...
- Java格式化CST时间(mysql date类型)
在从mysql导入数据时候,mysql里的日期是格林威治时间,普通格式化不行,这里总结一下格式化格林威治时间的方法: Date date = new Date(); System.out.printl ...
- 在Jquery里格式化Date日期时间数据
在Jquery里格式化Date日期时间数据: $(function(){ //当前时间格式化yyyy-MM-dd HH:mm:ss alert(timeStamp2String(new Date(). ...
- java代码--Date类获取当前时间-格式化输出
44:52 阅读数:2299 package cn.Date; import java.text.Format; import java.text.SimpleDateFormat; import ...
- 【记录】Mybatis Generator生成数据对象Date/TimeStamp 查询时间格式化
Mybatis Generator是很好的工具帮助我们生成表映射关联代码,最近博主遇到一个问题,找了很久才解决, 就是用Mybatis Generator生成实体类的时候,Date 时间无法格式化输出 ...
随机推荐
- ubuntu安装matlab
https://blog.csdn.net/qq_36982160/article/details/78397514 https://blog.csdn.net/weixin_40294256/art ...
- Andrew NG 机器学习编程作业4 Octave
问题描述:利用BP神经网络对识别阿拉伯数字(0-9) 训练数据集(training set)如下:一共有5000个训练实例(training instance),每个训练实例是一个400维特征的列向量 ...
- oracle查看表空间数据文件使用情况
-- 查看表空间数据文件使用情况 select a.*, round(a.usedgb/a.maxgb*100) || '%' usedPer from ( select t.TABLESPACE_N ...
- Kaldi中的L2正则化
steps/nnet3/train_dnn.py --l2-regularize-factor 影响模型参数的l2正则化强度的因子.要进行l2正则化,主要方法是在配置文件中使用'l2-regulari ...
- 检查CentOS7定时任务是否启用并执行过
1 监控cron状态 service crontab status #如果没有开启执行 service crontab start 正常开启的状态 2 检查执行日志,过滤自己配置的定时任务脚本关键字 ...
- NPOI2.2.0.0实例详解(九)—设置EXCEL单元格【时间格式】
原文:http://blog.csdn.net/xxs77ch/article/details/50245391 using System; using System.Collections.Gene ...
- linux 查看文件夹大小
参考链接: http://www.cnblogs.com/iconfig/p/4863063.html
- Centos 02 操作系统 & Linux安装
操作系统的概念 操作系统是沟通使用者和硬件之间传递信息的工具或程序,是电子计算机系统负责支撑应用程序运行环境以及用户操作环境的基础系统软件 硬件 ==> 系统核心 ==> 命令解释器she ...
- Spring重温(一)--Spring快速入门
1.spring官网(https://repo.spring.io)下载依赖jar. 2.配置spring环境时还需要commons-logging相关jar. 3.打开eclise创建一个工程,并将 ...
- P5239 回忆京都
题目地址:P5239 回忆京都 杨辉三角即组合数的"打表"形式 再求一个二维前缀和 然后处理一下负数即可(因为在求前缀和的过程中有减法) #include <bits/std ...