码迷,mamicode.com
首页 > Web开发 > 详细

js时间戳转换日期格式

时间:2021-03-03 12:25:04      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:日期格式   pre   this   second   mat   转换   new   time   日期格   

let time=1614733234043
let newTime=this.formatDate(time)

formatDate(date) {
let nowdate = new Date(date);
let YY = nowdate.getFullYear() + ‘-‘;
let MM = (nowdate.getMonth() + 1 < 10 ? ‘0‘ + (nowdate.getMonth() + 1) : nowdate.getMonth() + 1) + ‘-‘;
let DD = (nowdate.getDate() < 10 ? ‘0‘ + (nowdate.getDate()) : nowdate.getDate());
let hh = (nowdate.getHours() < 10 ? ‘0‘ + nowdate.getHours() : nowdate.getHours()) + ‘:‘;
let mm = (nowdate.getMinutes() < 10 ? ‘0‘ + nowdate.getMinutes() : nowdate.getMinutes()) + ‘:‘;
let ss = (nowdate.getSeconds() < 10 ? ‘0‘ + nowdate.getSeconds() : nowdate.getSeconds());
return YY + MM + DD +" "+hh + mm + ss;
},

js时间戳转换日期格式

标签:日期格式   pre   this   second   mat   转换   new   time   日期格   

原文地址:https://www.cnblogs.com/xb130460/p/14472525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!