db-tutorial/utils/modules/fn.js

26 lines
749 B
JavaScript
Raw Permalink Normal View History

2022-04-11 16:52:35 +08:00
// 类型判断
2023-08-18 20:37:16 +08:00
exports.type = function (o) {
2022-04-11 16:52:35 +08:00
var s = Object.prototype.toString.call(o)
return s.match(/\[object (.*?)\]/)[1].toLowerCase()
}
2023-08-18 20:37:16 +08:00
// 修复date时区格式的问题
exports.repairDate = function (date) {
date = new Date(date)
return `${date.getUTCFullYear()}-${zero(date.getUTCMonth() + 1)}-${zero(date.getUTCDate())} ${zero(
date.getUTCHours()
)}:${zero(date.getUTCMinutes())}:${zero(date.getUTCSeconds())}`
2022-04-11 16:52:35 +08:00
}
// 日期的格式
exports.dateFormat = function (date) {
2023-08-18 20:37:16 +08:00
return `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero(date.getDate())} ${zero(date.getHours())}:${zero(
date.getMinutes()
)}:${zero(date.getSeconds())}`
2022-04-11 16:52:35 +08:00
}
// 小于10补0
2023-08-18 20:37:16 +08:00
function zero(d) {
return d.toString().padStart(2, '0')
}