时间格式化
来源:互联网 发布:linux c 获取系统时间 编辑:程序博客网 时间:2024/06/07 10:57
const Format = function (date, fmt) { //date要格式化的时间戳、fmt格式化样式 const obj= { 'M+': date.getMonth() + 1, //月 'd+': date.getDate(), //天 'h+': date.getHours(), //时 'm+': date.getMinutes(), //分 's+': date.getSeconds(), //秒 'q+': Math.floor((date.getMonth() + 3) / 3), //季度 'S': date.getMilliseconds() //毫秒 } if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '')).substr(4 - RegExp.$1.length) } for (const key in obj) { if (new RegExp('(' + key + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (obj[key]) : (('00' + obj[key]).substr(('' + obj[key]).length))) } } return fmt}
调用:
Format(new Date(), 'yyyy-MM-dd hh:mm:ss')//2017-06-33 16:30:00
阅读全文
0 0
- 格式化时间
- 格式化时间
- 时间格式化
- 格式化时间
- 时间格式化
- 格式化时间
- 格式化时间
- 格式化时间
- 格式化时间
- 格式化时间
- 时间格式化
- 时间格式化
- 格式化时间
- 时间格式化
- 时间格式化
- 时间格式化
- 时间格式化
- 时间格式化
- hive在客户端执行总是报告找不到类
- 【备忘】2017年最新 EthicalHacking A-Z黑客教程合集
- iOS开发网络篇—数据缓存
- udp_server
- 为什么session.close(),之后不进行事务回滚
- 时间格式化
- PCB电源
- PHP使用日期时间扩展库Carbon人性化显示时间
- 悠百佳加盟是骗子,害人不浅专骗血汗钱!
- 插入
- 使用Gradle构建web项目
- 破解Mac版MyEclipse-2017-ci3
- 互联网协议学习笔记
- SGI STL 内存管理