Skip to content

Commit

Permalink
refactor: 重写 formatDateTime 工具函数
Browse files Browse the repository at this point in the history
  • Loading branch information
pany-ang committed Nov 11, 2024
1 parent 6f2fbf4 commit 6680e72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/utils/datetime.ts
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 0 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import dayjs from "dayjs"
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 变量 */
export const getCssVariableValue = (cssVariableName: string) => {
let cssVariableValue = ""
Expand Down

0 comments on commit 6680e72

Please sign in to comment.