mirror of
https://github.com/StepanovPlaton/AboutMe.git
synced 2026-04-04 12:50:49 +04:00
Initial commit
This commit is contained in:
24
src/utils/date.ts
Normal file
24
src/utils/date.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { langToLocaleMap } from "@i18n/language";
|
||||
import { getDefaultLanguage } from "./language";
|
||||
|
||||
|
||||
export function formatDateToYYYYMMDD(date: Date): string {
|
||||
return date.toISOString().substring(0, 10);
|
||||
}
|
||||
|
||||
// 国际化日期格式化函数
|
||||
export function formatDateI18n(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
const lang = getDefaultLanguage();
|
||||
|
||||
// 根据语言设置不同的日期格式
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
};
|
||||
|
||||
// 使用统一的语言配置获取 locale
|
||||
const locale = langToLocaleMap[lang] || "en-US";
|
||||
return date.toLocaleDateString(locale, options);
|
||||
}
|
||||
Reference in New Issue
Block a user