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’)
相關文章:
