I have ISO timezone string say "2019-11-08T14:44:12+0530"
I need it to convert into
08-11-2019 14:44:12 GMT+0530 (IST)
with or without moment?
Any help is appreciated.
You can use Moment JS to format the date like this
moment(new Date()).format("DD-MM-YYYY HH:mm:ss Z")
//08-11-2019 15:43:30 +05:30
Please use this Fiddle - https://jsfiddle.net/Ayyub/6zv2wkgo/19/
First you need to know the time zone. With that example, you only have the offset (+0530). For example, you can use the time zone "Asia/Calcutta".
Using momentjs and moment timezone , you can use this:
moment('2019-11-08T14:44:12+0530').tz("Asia/Calcutta").format('DD-MM-YYYY HH:mm:ss [GMT]Z (z)');
The output will be "08-11-2019 14:44:12 GMT+05:30 (IST)"
If you want to use the user's time zone, you can use moment.tz.guess()
.
moment('2019-11-08T14:44:12+0530').tz(moment.tz.guess()).format('DD-MM-YYYY HH:mm:ss [GMT]Z (z)');
In my case, the output will be "08-11-2019 09:14:12 GMT+00:00 (WET)"
, because i am in a different time zone.
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.