本文介绍了js中的弃用警告-未采用公认的ISO格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到警告,提示提供的值不是公认的ISO格式.我今天用矩函数更改了变量,但仍然无法正常工作.
I'm getting a warning that a value provided to moment is not in a recognized ISO format. I changed my variable today with the moment function and still it doesn't work.
这是警告错误:
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!
他们在这里讨论警告消息.
要获得一致的结果来解析除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").
String + Formats (multiple formats)
If you have more than one format, check out their String + Formats (with an 's').
moment("12-25-1995", ["MM-DD-YYYY", "YYYY-MM-DD"]);
请查看文档以获取更具体的内容.
Please checkout the documentation for anything more specific.
结帐在区域中解析,等效时区文档.
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中的弃用警告-未采用公认的ISO格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!