[英]Convert my given ISO date to required format along with timezone name
I have ISO timezone string say "2019-11-08T14:44:12+0530"我有 ISO 时区字符串说“2019-11-08T14:44:12+0530”
I need it to convert into我需要它转换成
08-11-2019 14:44:12 GMT+0530 (IST) 2019 年 8 月 11 日 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 JS 像这样格式化日期
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/请使用这个小提琴 - https://jsfiddle.net/Ayyub/6zv2wkgo/19/
First you need to know the time zone.首先你需要知道时区。 With that example, you only have the offset (+0530).
在该示例中,您只有偏移量 (+0530)。 For example, you can use the time zone "Asia/Calcutta".
例如,您可以使用时区“亚洲/加尔各答”。
Using momentjs and moment timezone , you can use this:使用momentjs和moment timezone ,您可以使用:
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)"
output 将是
"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.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.就我而言, output 将是
"08-11-2019 09:14:12 GMT+00:00 (WET)"
,因为我在不同的时区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.