I've got the following javascript code utilizing the moment.js library. We've been having issues with conversions to/from utc. The code below returns this result:
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.
1: 2014-11-17T19:16:00+00:00
2: 2014-11-17T19:16:00+00:00
3: 2014-11-17T13:16:00-06:00
Why would the first one return the same but give the deprecated warning? I'm using an ISO string.
Code:
var r = {Start:'2014-11-17T20:47:00Z', End:'2014-11-17T19:16:00Z'};
console.log(moment(r.Start).local());
var e = moment(r.Start);
var f = moment(r.End);
var res = {exDate: moment(e).format("MM/DD/YYYY"),
exStartTime: moment(e).format("MM/DD/YYYY hh:mm A"),
exEndTime: moment(f).format("MM/DD/YYYY hh:mm A")}
console.log(res );
console.log("1: " + moment(res.exEndTime).utc().format());
console.log("2: " + moment.utc(res.exEndTime).format());
console.log("3: " + moment(res.exEndTime).format()); // testing default local format.
Errors are because of wrapping date already wrapped with moment. You should use moment like this:
The errors are produced by the last three lines. For example, when you call
moment(res.exEndTime)
is already a string formatted asMM/DD/YYYY hh:mm A
. You are also callingmoment
redundantly. Essentially, you have:That's too many moments!