Wednesday, January 8, 2014

moment() versus moment.utc()

You may notice that in this:

var foo = moment.toDate();
var bar = moment.utc().toDate();

 
 

...foo and bar are basically the same thing. Perhaps you crave a hack like this:

var baz = new Date(moment.utc().format('YYYY-MM-DD HH:mm:ss'));

 
 

This stuff became an issue for me today when handing JavaScript dates to a library that then wrote them to a Web SQL database where the offsets were not maintained. About one sixth of the way down http://momentjs.com/docs/ there are some further details on moment() versus moment.utc().

No comments:

Post a Comment