gpt4 book ai didi

javascript - 时刻时区.js :476 Moment Timezone has no data for Asia/Jerusalem

转载 作者:行者123 更新时间:2023-12-01 02:04:24 24 4
gpt4 key购买 nike

我正在使用moments-timezone.js

但我得到了这个异常(exception):

moment-timezone.js:476 Moment Timezone has no data for Asia/Jerusalem

我去了tz references

我看到亚洲/耶路撒冷存在。

那么问题出在哪里呢?

toolFilters.filter('dateAccordingToTimeZone', function ($filter) {
// Gets the number of milliseconds pass from 1970 and convert it to time according to given timezone, currently
// supported “Asia/Jerusalem” and “America/Los_Angeles”
return function (milliSeconds, timeZoneId) {
if (milliSeconds == 0) {
return "";
}
var timeInt = parseInt(milliSeconds, 10);
var response = "";

if (timeZoneId === undefined) {
response = moment(timeInt);

} else if (timeZoneId.includes("/")) { //like "America/New_York"
response = moment.tz(timeInt, timeZoneId);

} else if (timeZoneId.includes("GMT")) {
var offset = timeZoneId.substring(3); //like "GMT-08:00"
response = moment(timeInt).utcOffset(offset);

} else {
response = moment(timeInt);
}

var response = response.format('MMM D, YYYY H:mm:ss');
console.log(response);
return response;
}

我有这些进口:

<script src="bower_components/moment/moment.js"></script> 
<script src="bower_components/moment-timezone/moment-timezone.js"></script>

最佳答案

您需要 moment-timezones-with-data.js 库

http://momentjs.com/timezone/

没有它,它就没有所有国际时区,因为他们不想强制拥有所有时区数据。

Working with moment-with-data

console.log(moment.tz('Asia/Jerusalem'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.16/moment-timezone-with-data.min.js"></script>

Failing without the data

  console.log(moment.tz('Asia/Jerusalem'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.16/moment-timezone.js"></script>

希望这有帮助!

关于javascript - 时刻时区.js :476 Moment Timezone has no data for Asia/Jerusalem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50233212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com