在时刻js的弃用警告 [英] Deprecation warning in moment js

查看:2136
本文介绍了在时刻js的弃用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助我在我的代码上收到警告,提供的值不是公认的ISO格式。并且我今天使用时刻功能更改我的变量但仍然不起作用。

I need help I'm getting a warning on my code that has a value provided is not in a recognized ISO format. and I change my variable today with moment function and still it doesn't work.

这是警告错误


弃用警告:提供的值不是公认的ISO格式。时刻构造回落到js Date(),这在所有浏览器和版本中都不可靠。不鼓励使用非ISO日期格式,并将在即将发布的主要版本中删除。请参阅 http://momentjs.com/guides/#/warnings/js-date/ 了解更多信息。
参数:
[0] _isAMomentObject:true,_isUTC:true,_useUTC:true,_l:undefined,_ i:2016-9-26 19:30,_f:undefined,_strict:undefined,_locale: [object Object]

Deprecation warning: value provided is not in a recognized ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. Arguments: [0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: 2016-9-26 19:30, _f: undefined, _strict: undefined, _locale: [object Object]



 var entryDate = new Date();
 var currentDate = entryDate.getDate();

        function between(x,min,max) { 
            return x.valueOf() >= min.valueOf() && x < max.valueOf();
        };

        $("#custom1").change(function(){
            if ($("#custom1 :selected").val() == "AU" ) {
                var keyword = "";

                var aus1_s = moment.tz('2016-9-26 19:30', 'Australia/Sydney');              
                var aus2_s = moment.tz('2016-10-2 19:30', 'Australia/Sydney');              
                var aus3_s = moment.tz('2016-10-9 19:30', 'Australia/Sydney');                  
                var aus4_s = moment.tz('2016-10-16 19:30', 'Australia/Sydney');                 
                var aus5_s = moment.tz('2016-10-23 19:30', 'Australia/Sydney');
                var aus6_s = moment.tz('2016-10-30 19:30', 'Australia/Sydney');
                var aus6_e = moment.tz('2016-11-5 19:30', 'Australia/Sydney');
            } 

            else if ($("#custom1 :selected").val() == "NZ" ) {
                var aus1_s =  moment.tz('2016-9-28 20:30', 'Pacific/Auckland');
                var aus2_s =  moment.tz('2016-10-4 20:30', 'Pacific/Auckland');
                var aus3_s =  moment.tz('2016-10-11 20:30', 'Pacific/Auckland');
                var aus4_s =  moment.tz('2016-10-18 20:30', 'Pacific/Auckland');
                var aus5_s =  moment.tz('2016-10-25 20:30', 'Pacific/Auckland');
                var aus6_s =  moment.tz('2016-11-2 20:30', 'Pacific/Auckland');
                var aus6_e =  moment.tz('2016-11-9 20:30', 'Pacific/Auckland');
            }

            else {
                $("#entryEquals").val("");
                return false;
            }

           var today = moment();

            switch (true) {
                case between (today, aus1_s, aus2_s):
                keyword = "RElYT04=";
                break;

                case between (today, aus2_s, aus3_s):
                keyword = "QlJJREU=";
                break;

                case between (today, aus3_s, aus4_s):
                keyword = "U1lETkVZ";
                break;

                case between (today, aus4_s, aus5_s):
                keyword = "R1JPT00=";
                break;

                case between (today, aus5_s, aus6_s):
                keyword = "V0VERElORw==";
                break;

                case between (today, aus6_s, aus6_e):
                keyword = "VExD";
                break;

                default:
                $("#entryEquals").val("");
                break;
            }

        $("#entryEquals").val(keyword);

        });


推荐答案

查看他们所有精彩的文档!

Check out all their awesome documentation!

以下是他们讨论警告信息


警告:浏览器支持解析字符串是不一致。因为没有关于应该支持哪些格式的规范,所以在某些浏览器中有效的方法在其他浏览器中不起作用。

Warning: Browser support for parsing strings is inconsistent. Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers.

为了解析除ISO 8601字符串以外的任何其他内容的一致结果,你应该使用字符串+格式

For consistent results parsing anything other than ISO 8601 strings, you should use String + Format.



moment("12-25-1995", "MM-DD-YYYY");



字符串+格式(多种格式)



如果您有多种格式,请查看他们的字符串+格式(用's')。


如果您不知道输入字符串的确切格式,但知道它可能是很多,你可以使用一系列格式。

If you don't know the exact format of an input string, but know it could be one of many, you can use an array of formats.



moment("12-25-1995", ["MM-DD-YYYY", "YYYY-MM-DD"]);

请查看文档以获取更具体的信息。

Please checkout the documentation for anything more specific.

结帐解析区域,时区的等效文档。

Checkout Parsing in Zone, the equivalent documentation for timezones.


moment.tz构造函数占用所有与矩构造函数相同的参数,但使用最后一个参数作为时区标识符。

The moment.tz constructor takes all the same arguments as the moment constructor, but uses the last argument as a time zone identifier.



var b = moment.tz("May 12th 2014 8PM", "MMM Do YYYY hA", "America/Toronto");

编辑

//...
var dateFormat = "YYYY-M-D H:m"; //<-------- This part will get rid of the warning.
var aus1_s, aus2_s, aus3_s, aus4_s, aus5_s, aus6_s, aus6_e;
if ($("#custom1 :selected").val() == "AU" ) {
    var region = 'Australia/Sydney';

    aus1_s = moment.tz('2016-9-26 19:30', dateFormat, region);              
    aus2_s = moment.tz('2016-10-2 19:30', dateFormat, region);              
    aus3_s = moment.tz('2016-10-9 19:30', dateFormat, region);                  
    aus4_s = moment.tz('2016-10-16 19:30', dateFormat, region);                 
    aus5_s = moment.tz('2016-10-23 19:30', dateFormat, region);
    aus6_s = moment.tz('2016-10-30 19:30', dateFormat, region);
    aus6_e = moment.tz('2016-11-5 19:30', dateFormat, region);
} else if ($("#custom1 :selected").val() == "NZ" ) {
    var region = 'Pacific/Auckland';

    aus1_s =  moment.tz('2016-9-28 20:30', dateFormat, region);
    aus2_s =  moment.tz('2016-10-4 20:30', dateFormat, region);
    aus3_s =  moment.tz('2016-10-11 20:30', dateFormat, region);
    aus4_s =  moment.tz('2016-10-18 20:30', dateFormat, region);
    aus5_s =  moment.tz('2016-10-25 20:30', dateFormat, region);
    aus6_s =  moment.tz('2016-11-2 20:30', dateFormat, region);
    aus6_e =  moment.tz('2016-11-9 20:30', dateFormat, region);
}
//...

这篇关于在时刻js的弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆