给定时区的 moment JS 和 moment-timezone JS 解析和显示问题

时间:2021-05-15 18:24:52

标签: reactjs date datetime momentjs moment-timezone

我正在尝试在成员的首选时区格式化给定的 UTC 日期。

输入:UTC 日期 - 日期中的任何位置都没有时区指示符,例如“2014-09-08T08:02:17-05:00”,它只是假设为UTC

输出:用户首选时区的字符串,最好带有 3 个字符的时区缩写,如 EST 或 PDT。我真的不想显示 +01:00 或类似的内容。理想的例子是 9/8/2014 8:02am EST

我可以使用 moment 或 moment-timezone 库,无论什么都行。

我熟悉并理解这个问题,但似乎无法找到我喜欢的解决方法。 https://github.com/moment/moment/issues/162

moment
  .utc(modifiedDate)            // a UTC date in some format
  .tz()                         // not sure what (if anything) to put here
  .utcOffset(userPreference)    // userPreference could be something like -5 or +2 or whatever 
                                // that's the easiest for me to store in a settings profile
  .format(userPreferredFormat)  // MM/DD/YYYY h:mm:ss a ZZ - any kind of format that I allow them to choose

那么谁能提供更好的解决方案?

谢谢!

0 个答案:

没有答案
相关问题