Formatting ISODate from Mongodb

后端 未结 4 1996
离开以前
离开以前 2020-11-30 01:23

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

4条回答
  •  青春惊慌失措
    2020-11-30 01:56

    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()
    

提交回复
热议问题