您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

在js中如何实现转换时间戳格式

2025/9/11 0:19:11发布14次查看
下面我就为大家分享一篇js实现把时间戳转换为yyyy-mm-dd hh:mm 格式(es6语法),具有很的参考价值,希望对大家有所帮助
如下所示:
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中如何实现转换时间戳格式的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product