util.js 文件
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatDate = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return [year, month, day].map(formatNumber).join('-')
}
module.exports = {
formatTime: formatTime,
formatDate: formatDate,
}
// 要查询日期的js文件
var date = require('../../utils/util.js')
console.log(date.formatDate(new Date()))
console.log(date.formatTime(new Date()))
// 2020-12-05
// 2020-12-05 22:24:10