javascript - 如何把CST时间快速的转成时间戳
问题描述
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’)
相关文章:
1. java - 怎么处理前台要展示,但是数据库表没有该字段的实体类冗余属性呢?2. boostrap怎么在移动端不显示sidebar?3. android - 使用listview加载不同item,数据填充错误。4. python3.x - python中的虚拟环境怎样设置一直处于激活状态5. javascript - 读js权威指南“作为值得函数”产生了疑惑,求释疑6. javascript - 为什么 process.stdin 会有 write 方法◔ ‸◔?7. python中merge后文件莫名变得非常大8. file - Python如何读文件内容修改后写回原文件9. 请问带渐变背景的进度条如何实现?求给点思路10. python - UTC格式转换成本地时间