I parse dates I get from an API with Moment, and I need to sort the array when I'm done collecting the data. I currently have this:
myobject.name = name;
myobject.time = Moment(ajaxinfo.startdate).format('DD/MM/YYYY');
array.push(myobject);
// ... more data is added ...
array.sort((left, right) => {
return Moment.utc(left.time).diff(Moment.utc(right.time));
});
ajaxinfo.startdate
is a string that I get from an API, and it looks like "2018-01-28T13:00:00+00:00"
But the above code doesn't work. It gives me a warning:
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment
construction falls back to js Date()
, which is not reliable across all browsers and versions. Non RFC2822/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.
How can I make it work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…