抽取公共方法
Siona
1. CommonJS 方法类
// src/utils/common.ts
import dayjs from "dayjs";
let CommonJS = {}
function conversionUtcDate(date, type, fmt) {
if (type === 'local') { // 传入 local 则将 UTC 时间转换为本地时间
// return dayjs.utc(date).local().format('YYYY-MM-DD HH:mm:ss')
if (fmt) {
return dayjs.utc(date).local().format(fmt)
} else {
return dayjs.utc(date).local()
}
} else if (type === 'UTC') { // 传入 UTC 则将时间转换为 UTC 时间
return dayjs(date).utc().format()
}
}
CommonJS.conversionUtcDate = (date, type, fmt) => conversionUtcDate(date, type, fmt)
export default CommonJS