moment.js - How to parse a date string string with a text timezone like 'PST'?

橙三吉。 提交于 2019-12-12 13:25:13

问题


I have a date string from an API containing a timezone using abbreviations:

"01/16/2018 12:15pm PST"

Moment.js seems to ignore the timezone though, even if I use the z timezone input parsing string. That only seems to handle timezones strings that are time offsets like -10:00

For example, I would expect these two commands to return different values, because they have different timezone strings ('PST' and 'UTC')

moment('01/01/1990 02:03pm PST', 'MM/DD/YYYY hh:mma z').format('h:mm A')
moment('01/01/1990 02:03pm UTC', 'MM/DD/YYYY hh:mma z').format('h:mm A')

But they both return "2:03 PM"

I'm also using moment-timezone, as in import moment from 'moment-timezone';, but this does not seem to add the parsing functionality for timezone strings.

来源:https://stackoverflow.com/questions/48658068/moment-js-how-to-parse-a-date-string-string-with-a-text-timezone-like-pst

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!