javascript - 如何把CST時(shí)間快速的轉(zhuǎn)成時(shí)間戳
問題描述
Thu Jun 15 2017 14:35:48 GMT+0800 (CST)
比如這樣的一個(gè)時(shí)間,現(xiàn)在用的VUE element插件,時(shí)間不知為啥出來的都是這個(gè)格式,有沒有簡單點(diǎn)的轉(zhuǎn)換方法
問題解答
回答1:new Date(’Thu Jun 15 2017 14:35:48 GMT+0800 (CST)’).getTime()附上一個(gè)函數(shù)
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’)
相關(guān)文章:
1. javascript - 一排三個(gè)框,各個(gè)框的間距是15px,距離外面的白框間距也是15px,這個(gè)css怎么寫?2. mysql函數(shù)unix_timestamp如何處理1970.1.1以前的數(shù)據(jù)?3. 在mac下出現(xiàn)了兩個(gè)docker環(huán)境4. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項(xiàng)5. 怎樣使留言的數(shù)據(jù)與登錄的用戶名,密碼保持一致(在數(shù)據(jù)庫上是一行的)。6. java servlet后臺導(dǎo)出上萬條數(shù)據(jù)到excel,太慢!求解7. mysql money 插入數(shù)據(jù)為什么報(bào)錯(cuò)?8. java - 關(guān)于使用POI解析excel中的時(shí)間格的值9. 求:阿里云服務(wù)器windows+小皮(phpstudy)+laravel部署方案(教程)10. 請問永久和臨時(shí)重定向有什么區(qū)別
