如下所示:
function formatdate(date,fmt) { if(/(y+)/.test(fmt)){ fmt = fmt.replace(regexp.$1,(date.getfullyear()+'').substr(4-regexp.$1.length)); } let o = { 'm+':date.getmonth() + 1, 'd+':date.getdate(), 'h+':date.gethours(), 'm+':date.getminutes(), 's+':date.getseconds() }; // 遍历这个对象 for(let k in o){ if(new regexp(`(${k})`).test(fmt)){ // console.log(`${k}`) console.log(regexp.$1) let str = o[k] + ''; fmt = fmt.replace(regexp.$1,(regexp.$1.length===1)?str:padleftzero(str)); } } return fmt;};function padleftzero(str) { return ('00'+str).substr(str.length);}
let timenow = 1514374627*1000
let newtime = new date(timenow)
formatdate(newtime,'yyyy-mm-dd hh:mm') //2017-12-27 19:37
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
使用vue2.0.js实现多级联动选择器
通过javascript实现比较同一天的时间大小
在react、vue项目中如何使用svg
使用react实现分页组件
vue2实现二级省市联动选择
在mint-ui中使用时间插件及获取选择值
在vue中全选实现数据的绑定及获取
详解讲解使用jest测试react native组件
以上就是在js中如何实现转换时间戳格式的详细内容。
