From 27f2209e8722107b4f4cd02b03d143b134b9ee32 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Wed, 28 Feb 2024 04:27:32 +0000 Subject: [PATCH] fix(core): date formatter timezone issue (#5936) date seems not hornoring the locale browser's locale when parsing date string like "2024-02-28". fixed by using dayjs instead. Fix incorrect journal title issue --- packages/frontend/core/src/utils/intl-formatter.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/frontend/core/src/utils/intl-formatter.ts b/packages/frontend/core/src/utils/intl-formatter.ts index b0ebae97e6..d25de98a78 100644 --- a/packages/frontend/core/src/utils/intl-formatter.ts +++ b/packages/frontend/core/src/utils/intl-formatter.ts @@ -1,3 +1,5 @@ +import dayjs from 'dayjs'; + const timeFormatter = new Intl.DateTimeFormat(undefined, { timeStyle: 'short', }); @@ -9,9 +11,9 @@ const dateFormatter = new Intl.DateTimeFormat(undefined, { }); export const timestampToLocalTime = (ts: string | number) => { - return timeFormatter.format(new Date(ts)); + return timeFormatter.format(dayjs(ts).toDate()); }; export const timestampToLocalDate = (ts: string | number) => { - return dateFormatter.format(new Date(ts)); + return dateFormatter.format(dayjs(ts).toDate()); };