refactor: 重写 formatDateTime 工具函数
This commit is contained in:
parent
6f2fbf4a90
commit
6680e72645
9
src/utils/datetime.ts
Normal file
9
src/utils/datetime.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import dayjs from "dayjs"
|
||||||
|
|
||||||
|
const INVALID_DATE = "N/A"
|
||||||
|
|
||||||
|
/** 格式化日期时间 */
|
||||||
|
export const formatDateTime = (datetime: string | number | Date = "", template: string = "YYYY-MM-DD HH:mm:ss") => {
|
||||||
|
const day = dayjs(datetime)
|
||||||
|
return day.isValid() ? day.format(template) : INVALID_DATE
|
||||||
|
}
|
@ -1,11 +1,5 @@
|
|||||||
import dayjs from "dayjs"
|
|
||||||
import { removeConfigLayout } from "@/utils/cache/local-storage"
|
import { removeConfigLayout } from "@/utils/cache/local-storage"
|
||||||
|
|
||||||
/** 格式化时间 */
|
|
||||||
export const formatDateTime = (time: string | number | Date) => {
|
|
||||||
return time ? dayjs(new Date(time)).format("YYYY-MM-DD HH:mm:ss") : "N/A"
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 用 JS 获取全局 css 变量 */
|
/** 用 JS 获取全局 css 变量 */
|
||||||
export const getCssVariableValue = (cssVariableName: string) => {
|
export const getCssVariableValue = (cssVariableName: string) => {
|
||||||
let cssVariableValue = ""
|
let cssVariableValue = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user