Javascript 猫鼬中的日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8990595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dates in mongoose?
提问by Industrial
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
?
我知道我可以Date.now
在mongoose
模式中设置为默认值,但是还有哪些其他 Javascript 日期类型或所有日期都会自动转换为 mongodb 的标准格式 - ISOdate
?
Are there anything I should be concerned about when it comes to storing dates?
在存储日期方面有什么我应该关注的吗?
dates: {
created: {type: Date, default: Date.now},
}
Thanks
谢谢
采纳答案by alessioalex
The only thing you should take care of is converting the MongoDB/BSON UTC date to your local timezone (in case you need this).
您唯一应该注意的是将 MongoDB/BSON UTC 日期转换为您的本地时区(以防万一)。
For more info checkout: http://docs.mongodb.org/manual/reference/bson-types/#document-bson-type-date
有关更多信息结帐:http: //docs.mongodb.org/manual/reference/bson-types/#document-bson-type-date
回答by nihilism
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
您需要覆盖到new Date(req.body.time).toString()
,req.body.time 是时间格式月/日/年或月-日-年月前一天