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 formatNumber = n => { n = n.toString() return n[1] ? n : '0' + n } const formatChDate = date => { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() return year + '年' + month + '月' + day + '日' + [hour, minute].map(formatNumber).join(':') } const formatChDate1 = date => { var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() var hour = date.getHours() var minute = date.getMinutes() if (month < 10) { month = '0' + month } if (day < 10) { day = '0' + day } return year + '-' + month + '-' + day } // 是否为空对象 const isEmptyObject = obj => { var name for (name in obj) { return false } return true } module.exports = { formatTime: formatTime, formatChDate: formatChDate, isEmptyObject: isEmptyObject, formatChDate1: formatChDate1 }