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

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 ) );
主站蜘蛛池模板: 蓝田县| 苗栗市| 宽城| 石景山区| 类乌齐县| 饶河县| 天祝| 和林格尔县| 西城区| 甘泉县| 鄂州市| 融水| 浦江县| 凯里市| 和平区| 铜山县| 恩施市| 上林县| 左云县| 鸡东县| 海丰县| 喀什市| 和平区| 鄂托克前旗| 江门市| 延庆县| 汉沽区| 花莲县| 德化县| 遂川县| 惠州市| 嘉鱼县| 甘肃省| 温宿县| 建德市| 定襄县| 平顺县| 尚志市| 灯塔市| 静乐县| 青铜峡市|