2026-05-25 05:25:57 +08:00
|
|
|
function localeFor(lang: string): string {
|
2026-05-26 07:36:53 +08:00
|
|
|
const locales: Record<string, string> = {
|
|
|
|
|
zh: "zh-CN",
|
|
|
|
|
en: "en-US",
|
|
|
|
|
ja: "ja-JP",
|
|
|
|
|
ko: "ko-KR",
|
|
|
|
|
vi: "vi-VN",
|
|
|
|
|
id: "id-ID",
|
|
|
|
|
ms: "ms-MY",
|
|
|
|
|
};
|
|
|
|
|
return locales[lang] ?? "en-US";
|
2026-05-25 05:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatDate(iso: string, lang: string): string {
|
|
|
|
|
const d = new Date(iso);
|
|
|
|
|
return new Intl.DateTimeFormat(localeFor(lang), {
|
|
|
|
|
year: "numeric",
|
|
|
|
|
month: lang === "en" ? "short" : "numeric",
|
|
|
|
|
day: "numeric",
|
|
|
|
|
}).format(d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function formatTime(iso: string, lang: string): string {
|
|
|
|
|
const d = new Date(iso);
|
|
|
|
|
return new Intl.DateTimeFormat(localeFor(lang), {
|
|
|
|
|
hour: "numeric",
|
|
|
|
|
minute: "2-digit",
|
|
|
|
|
hour12: lang === "en",
|
|
|
|
|
}).format(d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function formatDateTime(iso: string, lang: string): string {
|
|
|
|
|
return `${formatDate(iso, lang)} ${formatTime(iso, lang)}`;
|
|
|
|
|
}
|