xz_angren/utils/util.js

43 lines
930 B
JavaScript
Raw Permalink Normal View History

2020-06-23 19:14:44 +08:00
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()
2020-06-23 19:14:44 +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 => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
2020-06-23 19:14:44 +08:00
return [year, month, day].map(formatNumber).join('-')
2020-06-23 19:14:44 +08:00
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
2020-06-23 19:14:44 +08:00
}
function indexOf(str, val) {
if (str.indexOf(val) != -1) {
return true;
} else {
return false;
}
}
function formatDuration(){
2020-06-23 19:14:44 +08:00
}
module.exports = {
formatTime: formatTime,
formatDate: formatDate,
indexOf: indexOf
}