zxytools
Version:
``` npm install it-tools
23 lines (18 loc) • 489 B
JavaScript
//定义格式化事件的函数
function dateFormta(date) {
const de = new Date(date)
const y = de.getFullYear()
const m = pad(de.getMonth() + 1)
const d = pad(de.getDate())
const hh = pad(de.getHours())
const mm = pad(de.getMinutes())
const ss = pad(de.getSeconds())
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
}
//定义一个补零的函数
function pad(n) {
return n < 10 ? '0' + n : n
}
module.exports = {
dateFormta
}