简体   繁体   中英

Convert ISO/UTC date to local by displaying timezone javascript/momentjs

I have a date in the format like 2019-05-18T19:30:00-0400 which I need to display as 05/18/2019 07:30 PM EST using momentjs or plain javascript. I tried several ways, for example, moment(new Date('2019-05-18T19:30:00-0400')).format('MM-DD-YYYY h:mm A zz')

It is impossible to determine a time zone from an offset alone. There are many offsets that belong to more than one time zone. Thus rendering an abbreviation is impossible.

See Time Zone != Offset in the timezone tag wiki for further details, and refer to the list of tz database time zones if you would like examples.

However, from your comments it appears you that you would also like to keep the same local time and offset as you are given. Moment can help with that part, using its (inappropriately named) parseZone function:

moment.parseZone("2019-05-18T19:30:00+0100").format("MM/DD/YYYY hh:mm A ZZ")
//=> "05/18/2019 07:30 PM +0100"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM