mirror of
https://github.com/m1ngsama/FUJI.git
synced 2025-12-24 10:51:27 +00:00
18 lines
677 B
TypeScript
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
|
|
}
|