![](/img/trans.png)
[英]How to convert a date to ISO format but with timezone info in place of the 'Z' in Javascript?
[英]Convert my given ISO date to required format along with timezone name
我有 ISO 时区字符串说“2019-11-08T14:44:12+0530”
我需要它转换成
2019 年 8 月 11 日 14:44:12 GMT+0530 (IST)
有或没有时刻?
任何帮助表示赞赏。
您可以使用 Moment JS 像这样格式化日期
moment(new Date()).format("DD-MM-YYYY HH:mm:ss Z")
//08-11-2019 15:43:30 +05:30
请使用这个小提琴 - https://jsfiddle.net/Ayyub/6zv2wkgo/19/
首先你需要知道时区。 在该示例中,您只有偏移量 (+0530)。 例如,您可以使用时区“亚洲/加尔各答”。
使用momentjs和moment timezone ,您可以使用:
moment('2019-11-08T14:44:12+0530').tz("Asia/Calcutta").format('DD-MM-YYYY HH:mm:ss [GMT]Z (z)');
output 将是"08-11-2019 14:44:12 GMT+05:30 (IST)"
如果要使用用户的时区,可以使用moment.tz.guess()
。
moment('2019-11-08T14:44:12+0530').tz(moment.tz.guess()).format('DD-MM-YYYY HH:mm:ss [GMT]Z (z)');
就我而言, output 将是"08-11-2019 09:14:12 GMT+00:00 (WET)"
,因为我在不同的时区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.