简体   繁体   English

firefox上的moment.js问题

[英]moment.js issue on firefox

This code works fine on chrome but does not work on firefox or IE. 此代码在chrome上工作正常,但在firefox或IE上不起作用。 Note that it works fine when I remove the "+00:00" 请注意,当我删除“+00:00”时它工作正常

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.0/moment.min.js"></script>
<script>
 var now = moment("Sun Jun 01 2016 05:00:00+00:00").format('ddd MMM DD YYYY HH:mm:ssZ');
 alert(now);
</script>

If you don't pass the format of the string to parse, you're relying on moment.js guessing the format and if it can't get something that looks like a valid date (it may still be incorrect), it will fall back to parsing by the built–in Date constructor, which is strongly recommended against. 如果你没有传递字符串的格式来解析,你依赖于moment.js猜测格式,如果它不能得到看起来像一个有效日期的东西(它可能仍然是不正确的),它将会下降回到内置的Date构造函数进行解析,强烈建议使用它。 The format method is for the output format, not the parse format. 格式方法用于输出格式,而不是解析格式。

To pass the format of the string to the moment.js parser, include it as the second argument: 要将字符串的格式传递给moment.js解析器,请将其包含为第二个参数:

moment("Sun Jun 01 2016 05:00:00+00:00",'ddd MMM DD YYYY HH:mm:ssZ').format(/*output format*/)

Note also that where it falls back to built–in parsing, the following warning is displayed in the console: 另请注意,在内置解析的情况下,控制台中会显示以下警告:

Deprecation warning: moment construction falls back to js Date. 弃用警告:时刻构建回落到日期。 This is discouraged and will be removed in upcoming major release. 这是不鼓励的,将在即将发布的主要版本中删除。 Please refer to https://github.com/moment/moment/issues/1407 for more info. 有关详细信息,请参阅https://github.com/moment/moment/issues/1407

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM