I have this date coming as string from API
{
"date": "2020-11-05T18:24:00-05:00"
}
I want this to be rendered as :
November 5, 2020, 6:24:00 PM EST
The issue is, I can't extract timezone name from this string to pass to Intl.DateTimeFormat()
Any thoughts?!
You can't get EST from -05:00 directly, without defining a context. Indeed, this offset could reference several time zones, see this list.
In the browser, you can let the time library to guess the time zone of your client:
var tz = moment.tz.guess(); // America/New_York, for example
var date = moment("2020-11-05T18:24:00-05:00").tz(tz)
.format("MMMM D, YYYY, h:mm:ss A z");
console.log(date); // November 5, 2020, 6:24:00 PM EST
Or you can define a time zone yourself.
Of course, the two solutions will not give you the same result depending on the time zone specified.