1

I need to display the browser local time with time zone in the following format: '10 Feb 23 10:07:04 EST'

When I do this:

new Date(uploadDateTime).toLocaleString('en-US')

it displays for me in PST

02/10/2023, 10:07:04 AM (Pacific Standard Time)

but my colleague in India sees

02/10/2023, 10:07:04 AM (India Standard Time)

It displays wrong format and we need an abbreviation of time zone like PST, IST instead of (Pacific Standard Time). Also I should not hard code to 'en-US' so it works globally.

I've tried this way:

new Date(uploadDateTime).toLocaleString(undefined, { timeZoneName: 'short' })

In this case instead of 'en-US' if you put

undefined

it should default to browser's locale timezone.

Now I see

02/10/2023, 10:07:04 AM PST

But in India it shows:

02/10/2023, 10:07:04 GMT +5:30

How do I format the date so it shows in the following format in any part of the world?

10 Feb 23 10:07:04 EST

BBeknaz0904
  • 29
  • 1
  • 1
  • 9
  • GMT +5:30 is accurate but not the named timezone. This answer is possibly relevant: https://stackoverflow.com/a/54813917/13762301 if you add the `timeZoneName` option. (If I specify `short` I get `GMT +1:00` but if I specify `long` I get `British Summer Time`) – pilchard Feb 10 '23 at 21:21

0 Answers0