今日分享时间戳格式化的方法:
//格式化日期时间 保留两位数
ismm(m){return m<10?'0'+m:m },
//时间格式化
timeFormatting(now){
var time = new Date(now);
var y = time.getFullYear();
var m = time.getMonth()+1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
let newTime = y+'-'+ this.ismm(m)+'-'+ this.ismm(d)+' '+ this.ismm(h)+':'+ this.ismm(mm);
return newTime;
},
其中时分秒补齐两位数。