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

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 ) );
主站蜘蛛池模板: 曲松县| 博乐市| 凌源市| 襄汾县| 江油市| 杭锦后旗| 盐山县| 德州市| 美姑县| 台北市| 五莲县| 巫山县| 门头沟区| 神农架林区| 灯塔市| 安福县| 玛多县| 西青区| 高雄县| 江达县| 时尚| 翼城县| 东丽区| 五家渠市| 昌宁县| 美姑县| 乐业县| 临沧市| 开封县| 杭锦后旗| 孟村| 鹤山市| 无为县| 四子王旗| 铜梁县| 青岛市| 杭锦后旗| 资中县| 龙口市| 光泽县| 都安|