Dates in mongoose?


Question

I know that I can set Date.now as a default value in a mongoose schema, but what other Javascript date types or are all dates automatically converted to mongodb´s standard format - ISOdate?

Are there anything I should be concerned about when it comes to storing dates?

dates: {
    created:  {type: Date, default: Date.now},
}

Thanks

1
21
1/24/2012 4:42:26 PM

Accepted Answer

The only thing you should take care of is converting the MongoDB/BSON UTC date to your local timezone (in case you need this).

For more info checkout: http://docs.mongodb.org/manual/reference/bson-types/#document-bson-type-date

18
5/13/2016 4:04:22 AM

you need cover to new Date(req.body.time).toString() , req.body.time is a time format month/day/year or month-day-year month before day


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon