Thursday 15 August 2013

node.js - Javascript momentjs convert UTC from string to Date Object -



node.js - Javascript momentjs convert UTC from string to Date Object -

folks, having hard time moment.js documentation.

record.lastmodified = moment.utc().format();

returns:

2014-11-11t21:29:05+00:00

which great, in utc... when store in mongo, gets stored string, not date object type, want.

what need is:

"lastmodified" : isodate("2014-11-11t15:26:42.965-0500")

but need native javascript object type, , store in mongo. right if store above, goes in string, not date object type.

i have tried moment.js. todate() function works, falls local timezone, , not giving me utc.

thanks!

not ideal solution, achieved same result, manually converting isodate object through monogo shell. need isodate comparison/query aggregating results, run script before running our aggregate scripts.

inserting local time string using moment().format().

"createddt" : "2015-01-07t17:07:43-05:00"`

converting isodate (utc) with:

var cursor = db.collection.find({createddt : {$exists : true}}); while (cursor.hasnext()){ var doc = cursor.next(); db.collection.update( {_id : doc._id}, {$set: {createddt : new isodate(doc.createddt)}}) }

results in

"createddt" : isodate("2015-01-07t22:07:43z")"

note time got converted t17:07:43-05:00 t22:07:43z

i not find solution inserting bson isodate format (which utc default) javascript directly, while inserting new document, seems available through pymongo & c#/java drivers though. trying maintainable solution

node.js mongodb momentjs

No comments:

Post a Comment