您的位置:首页技术文章
文章详情页

javascript - 如何把CST时间快速的转成时间戳

【字号: 日期:2023-06-02 14:36:58浏览:61作者:猪猪

问题描述

Thu Jun 15 2017 14:35:48 GMT+0800 (CST)

比如这样的一个时间,现在用的VUE element插件,时间不知为啥出来的都是这个格式,有没有简单点的转换方法

问题解答

回答1:

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;}// usageparseTime(new Date.getTime(), ’hh:mm’)

标签: JavaScript
相关文章: