- 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 ) );
推薦閱讀
- 人工智能工程化:應用落地與中臺構建
- 網絡綜合布線技術
- Hands-On Cybersecurity with Blockchain
- 大數據平臺異常檢測分析系統的若干關鍵技術研究
- 大型數據庫管理系統技術、應用與實例分析:SQL Server 2005
- 計算機系統結構
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- 基于32位ColdFire構建嵌入式系統
- 數據庫系統原理及應用教程(第5版)
- OpenStack Cloud Computing Cookbook
- Chef:Powerful Infrastructure Automation
- 軟件構件技術
- Citrix? XenDesktop? 7 Cookbook
- Flink原理與實踐
- Excel 2007終極技巧金典