官术网_书友最值得收藏!

Date type

Dates are stored as milliseconds with effect from January 1st, 1970 (epoch time). They are 64-bit signed integers, allowing for a range of 135 million years before and after 1970. A negative date value denotes a date before January 1st, 1970. The BSON specification refers to the Date type as UTC datetime.

Dates in MongoDB are stored in UTC. There isn't a timestamp with timezone datatype like in some relational databases. Applications that need to access and modify timestamps based on local time should store the timezone offset together with the date and offset dates on an application level.

In the MongoDB shell, this could be done this way using JavaScript:

var now = new Date();
db.page_views.save({date: now,
offset: now.getTimezoneOffset()});

And then applying the saved offset to reconstruct the original local time:

var record = db.page_views.findOne();
var localNow = new Date( record.date.getTime() - ( record.offset * 60000 ) );
主站蜘蛛池模板: 连江县| 留坝县| 邹城市| 永福县| 秦皇岛市| 深水埗区| 陆丰市| 兰西县| 凉山| 平舆县| 清原| 韶关市| 洪洞县| 宁明县| 邮箱| 义乌市| 平江县| 唐山市| 肇州县| 清涧县| 芷江| 忻州市| 江口县| 华亭县| 尚义县| 库伦旗| 锡林郭勒盟| 县级市| 潼关县| 专栏| 黑龙江省| 安庆市| 北票市| 交口县| 榆林市| 河津市| 张家口市| 荔波县| 旺苍县| 汝州市| 利津县|