In Mongodb I am storing date and time in ISODate format.
Which looks like this
ISODate("2012-07-14T01:00:00+01:00")
Using nodejs/javascript, how can I display the time component so I would get something like this
Time : 01:00
I am using momentjs to make this easier but from what I can tell momentjs does seem to support the ISODate format.
Thanks for you help.
This question is related to
javascript
node.js
mongodb
isodate
// from MongoDate object to Javascript Date object
var MongoDate = {sec: 1493016016, usec: 650000};
var dt = new Date("1970-01-01T00:00:00+00:00");
dt.setSeconds(MongoDate.sec);
MongoDB's ISODate() is just a helper function that wraps a JavaScript date object and makes it easier to work with ISO date strings.
You can still use all of the same methods as working with a normal JS Date, such as:
ISODate("2012-07-14T01:00:00+01:00").toLocaleTimeString()
// Note that getHours() and getMinutes() do not include leading 0s for single digit #s
ISODate("2012-07-14T01:00:00+01:00").getHours()
ISODate("2012-07-14T01:00:00+01:00").getMinutes()
Source: Stackoverflow.com