[英]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.