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

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 ) );
主站蜘蛛池模板: 龙胜| 哈巴河县| 黑河市| 皮山县| 漯河市| 潜江市| 文安县| 永清县| 大足县| 屏南县| 饶阳县| 保山市| 巢湖市| 潜山县| 南投县| 阳新县| 塘沽区| 德江县| 濉溪县| 金秀| 望江县| 六枝特区| 厦门市| 连平县| 沁水县| 乐平市| 涪陵区| 桃园市| 商河县| 广饶县| 封开县| 巨野县| 通渭县| 抚顺市| 枣阳市| 宕昌县| 金阳县| 太仆寺旗| 大石桥市| 赫章县| 安化县|