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
This commit is contained in:
Peng Xiao
2024-02-28 04:27:32 +00:00
parent 9e09166452
commit 27f2209e87

View File

@@ -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());
};