年与日时分秒各种格式 补0位的方法

 let startTime=new Date(this.seachObj.times[0])
 startTime=startTime.getFullYear() + '' + this.p(startTime.getMonth() + 1) + '' + this.p(startTime.getDate())+ ' '+this.p(startTime.getHours()) + ':' + this.p(startTime.getMinutes()) + ':' + this.p(startTime.getSeconds())
 let endTime=new Date(this.seachObj.times[1])
 endTime=endTime.getFullYear() + '' + this.p(endTime.getMonth() + 1) + '' + this.p(endTime.getDate())+ ' '+this.p(endTime.getHours()) + ':' + this.p(endTime.getMinutes()) + ':' + this.p(endTime.getSeconds())
 
 
补0方法
p (s) {
return s < 10 ? '0' + s : s;
},

猜你喜欢

转载自www.cnblogs.com/yn-cn/p/9248081.html