Angular Moment:Moment Timezone没有America / New_York的数据 [英] Angular Moment : Moment Timezone has no data for America/New_York
问题描述
从服务器收到的日期是 UTC
时区,我需要将其转换为特定的时区,例如: America / New_York
。以下是相同的代码
Date received from server is in UTC
timezone and I need to convert it to a particular timezone, for example : America/New_York
.Following is the code for same
<span class="bold" ng-bind="sess.date_time | amTimezone:'America/New_York' | amDateFormat:'h:mm a'"></span>
但是这样做我收到以下错误:
But on doing so I get the following error:
Moment Timezone has no data for America/New_York. See http://momentjs.com/timezone/docs/#/data-loading/.
但 America / New_York
是已知时区到时刻
但仍然要求我添加时区。
But America/New_York
is a known timezone to moment
but still it is asking me to add the Timezone.
推荐答案
您需要加载以下所有内容:
You need to load all of the following:
- 时刻
- moment-timezone
- 时区数据 for moment-timezone
- angular-moment
- moment
- moment-timezone
- time zone data for moment-timezone
- angular-moment
在 moment-timezone 主页上,有三种不同的发行版:时刻时区。
On the moment-timezone home page, there are available three different distributions of moment-timezone.
-
moment-timezone.js
是只是脚本。它不包含时区数据。如果您使用此发行版,则可以通过moment.tz.add
或moment.tz来提取您自己的时区数据。 .load
,如文档中所述。
moment-timezone.js
is just the script. It contains no time zone data. If you use this distribution, it's expected that you will pull in your own time zone data, either bymoment.tz.add
, ormoment.tz.load
, as described in the docs.
moment-timezone-with-data.js
包含来自 tz数据库的所有已知时区数据,针对上述版本在网站上。
moment-timezone-with-data.js
includes all known time zone data from the tz database, for the version mentioned on the web site.
moment-timezone-with-data-2012-2022.js
包括相同的tz数据,但截断到2012年到2022年。这是一个小得多的数据文件,足以满足大多数浏览器端应用程序的需要。
moment-timezone-with-data-2012-2022.js
includes the same tz data, but is truncated to just years 2012 through 2022. This is a much smaller data file, and is sufficient for the majority of browser-side applications.
每个都有缩小版本。
所以如果你得到Moment Timezone没有America / New_York的数据
,因为 America / New_York
是一个有效的TZ数据库标识符,那么你只需要没有为它加载数据。您可能正在使用 moment-timezone.js
而不向其添加数据。使用 moment.tz.add
包含时区数据,或者(更合适地)切换到已包含所有时区数据的文件之一。
So if you are getting "Moment Timezone has no data for America/New_York"
, since America/New_York
is a valid TZ database identifier, then you simply haven't loaded the data for it. You are probably using moment-timezone.js
without adding data to it. Either include time zone data with moment.tz.add
, or (more appropriately) switch to one of the files that already includes all time zone data.
但是,不要两者都做。时区数据只应加载一次,而moment-timezone脚本只应加载一次。如果您使用 moment-timezone-with-data.js
或 moment-timezone-with-data-2012-2022.js
,你不应该使用 moment-timezone.js
,因为该脚本已经包含在内。
However, do not do both. Time zone data should only be loaded once, and the moment-timezone scripts should only be loaded once. If you use either moment-timezone-with-data.js
or moment-timezone-with-data-2012-2022.js
, you should not be using moment-timezone.js
, as that script is already included.
这篇关于Angular Moment:Moment Timezone没有America / New_York的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!