- Mastering MongoDB 3.x
- Alex Giamas
- 151字
- 2021-08-20 10:10:50
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 ) );
推薦閱讀
- Cloud Analytics with Microsoft Azure
- 機(jī)器學(xué)習(xí)與大數(shù)據(jù)技術(shù)
- 嵌入式Linux上的C語(yǔ)言編程實(shí)踐
- 21天學(xué)通C#
- JSF2和RichFaces4使用指南
- Implementing Oracle API Platform Cloud Service
- Kubernetes for Developers
- 人工智能趣味入門(mén):光環(huán)板程序設(shè)計(jì)
- 新編計(jì)算機(jī)圖形學(xué)
- 手機(jī)游戲程序開(kāi)發(fā)
- Linux Shell編程從初學(xué)到精通
- 寒江獨(dú)釣:Windows內(nèi)核安全編程
- Building Google Cloud Platform Solutions
- Puppet 3 Beginner’s Guide
- FreeCAD [How-to]