Files
xuanzhi-wx/utils/util.js
2026-04-22 18:54:52 +08:00

33 lines
657 B
JavaScript

function formatDateTime(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(':')}`
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : `0${n}`
}
function maskToken(token) {
if (!token) {
return '未登录'
}
if (token.length <= 10) {
return token
}
return `${token.slice(0, 4)}...${token.slice(-4)}`
}
module.exports = {
formatDateTime,
maskToken
}