js一些时间工具类


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function formatNum(num) {
let res = Number(num);
return res < 10 ? '0' + res : res;
}
function getToday() {
let date = new Date();
let y = date.getFullYear();
let m = date.getMonth();
let d = date.getDate();
let hour = date.getHours();
let minutes = new Date().getMinutes();
let seconds = new Date().getSeconds();

date =y + '-' + this.formatNum(m + 1) + '-' + this.formatNum(d) + ' ' +this.formatNum(hour)+ ':' +this.formatNum(minutes)+":"+this.formatNum(seconds)

return date;
}

Author: pkq
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source pkq !
  TOC