From dd7a4e4eac6966a156336a6ece394d5c1fc0f70f Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 9 Mar 2023 16:00:17 +0800 Subject: [PATCH] Use local timezone for the date in the reader --- packages/web/lib/dateFormatting.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/web/lib/dateFormatting.ts b/packages/web/lib/dateFormatting.ts index 587db2e88..0ac9bff52 100644 --- a/packages/web/lib/dateFormatting.ts +++ b/packages/web/lib/dateFormatting.ts @@ -1,15 +1,19 @@ //https://github.com/you-dont-need/You-Dont-Need-Momentjs const locale = Intl.DateTimeFormat().resolvedOptions().locale || 'en-US' +// get the user's time zone +const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone export function formattedLongDate(rawDate: string): string { return new Intl.DateTimeFormat(locale, { dateStyle: 'long', + timeZone, }).format(new Date(rawDate)) } export function formattedShortDate(rawDate: string): string { return new Intl.DateTimeFormat(locale, { dateStyle: 'short', + timeZone, }).format(new Date(rawDate)) }