FUJI/src/utils.ts
2024-06-04 20:38:39 +08:00

18 lines
677 B
TypeScript

export function formatDate(dateString: string) {
const date = new Date(dateString)
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return year + " 年 " + month + " 月 " + day + " 日"
}
export function formatDateV2(date: string) {
// 创建一个Date对象
const d = new Date(date)
// 使用toLocaleString方法返回本地时间字符串
const localTime = d.toLocaleString("zh-CN", { year: "numeric", month: "2-digit", day: "2-digit" })
// 去掉字符串中的斜杠和空格
const formattedDate = localTime.replace(/\//g, "-").replace(/\s/g, "")
// 返回格式化后的日期
return formattedDate
}