扫码关注官方订阅号
Thu Jun 15 2017 14:35:48 GMT+0800 (CST)
比如这样的一个时间,现在用的VUE element插件,时间不知为啥出来的都是这个格式,有没有简单点的转换方法
new Date('Thu Jun 15 2017 14:35:48 GMT+0800 (CST)').getTime()附上一个函数
new Date('Thu Jun 15 2017 14:35:48 GMT+0800 (CST)').getTime()
function parseTime (timeStamp, format) { var date = new Date(timeStamp); var o = { 'M+' : date.getMonth() + 1, //month 'D+' : date.getDate(), //day 'h+' : date.getHours(), //hour 'm+' : date.getMinutes(), //minute 's+' : date.getSeconds(), //second 'S' : date.getMilliseconds() //millisecond } if(/(Y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); } for(var k in o) { if (new RegExp('('+ k +')').test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00'+ o[k]).substr((''+ o[k]).length)); } } return format; } // usage parseTime(new Date.getTime(), 'hh:mm')
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
new Date('Thu Jun 15 2017 14:35:48 GMT+0800 (CST)').getTime()
附上一个函数