且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Moment.js中的弃用警告-未采用公认的ISO格式

更新时间:2023-11-13 15:43:52

查看他们所有很棒的文档!

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.

结帐在区域中解析,等效时区文档.

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);
}
//...