2020-06-23 19:14:44 +08:00
|
|
|
const formatTime = date => {
|
2023-03-01 16:33:12 +08:00
|
|
|
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()
|
2020-06-23 19:14:44 +08:00
|
|
|
|
2023-03-01 16:33:12 +08:00
|
|
|
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
|
2020-06-23 19:14:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {*} date
|
|
|
|
*/
|
|
|
|
const formatDate = date => {
|
2023-03-01 16:33:12 +08:00
|
|
|
const year = date.getFullYear()
|
|
|
|
const month = date.getMonth() + 1
|
|
|
|
const day = date.getDate()
|
2020-06-23 19:14:44 +08:00
|
|
|
|
2023-03-01 16:33:12 +08:00
|
|
|
return [year, month, day].map(formatNumber).join('-')
|
2020-06-23 19:14:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const formatNumber = n => {
|
2023-03-01 16:33:12 +08:00
|
|
|
n = n.toString()
|
|
|
|
return n[1] ? n : '0' + n
|
2020-06-23 19:14:44 +08:00
|
|
|
}
|
|
|
|
|
2023-03-01 16:33:12 +08:00
|
|
|
function indexOf(str, val) {
|
|
|
|
if (str.indexOf(val) != -1) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-15 17:58:44 +08:00
|
|
|
}
|
|
|
|
function formatDuration(){
|
|
|
|
|
2020-06-23 19:14:44 +08:00
|
|
|
}
|
2023-03-01 16:33:12 +08:00
|
|
|
module.exports = {
|
|
|
|
formatTime: formatTime,
|
|
|
|
formatDate: formatDate,
|
|
|
|
indexOf: indexOf
|
|
|
|
}
|