2

The time is given in YYYY-MM-DDTHH:mm:ssZ format, for example 2023-04-30T16:00:00-05:00. And I want to display 2023-04-30 04:00 PM EST using dayjs.

How can I do that?

Ever Dev
  • 1,882
  • 2
  • 14
  • 34
  • 2
    I'm not sure this is completely possible. The `-05:00` part just represents a timezone offset, but you want the name of a timezone in your output. `-05:00` can refer to multiple different timezone names, not just `EST`. – Michael M. Apr 30 '23 at 19:37
  • 1
    `dayjs('2023-01-11T16:50:00-05:00').tz('America/Toronto').format('h:mm a z')` prints `4:50 pm EST` so I think this should be possible. – Ever Dev Apr 30 '23 at 19:40
  • I wish dayjs would provide `dayjs.tz.guess(string)` – Ever Dev Apr 30 '23 at 19:40
  • 1
    I wrote an answer a while back that attempted to convert between offset and name [over here](https://stackoverflow.com/questions/75512632/how-to-get-a-timezone-name-from-iso-string-in-javascript/75512963#75512963). I'm not well versed in day.js, but it seems that dayjs **is** able to convert between offset and name if you provide a locale-ish thing like `America/Toronto`. – Michael M. Apr 30 '23 at 19:42

0 Answers0