Skip to content

Commit 3e4c6c0

Browse files
authored
docs(FAQ): details about TimeZones
1 parent cef1784 commit 3e4c6c0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

docs/en/faq.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Frequently Asked Questions
2+
3+
## Why my TimeZone is converted to UTC?
4+
MongoDB [stores times in UTC by default](https://docs.mongodb.com/manual/reference/bson-types/#document-bson-type-date), and will convert any local time representations into this form.
5+
Applications that must operate or report on some unmodified local time value may store the time zone alongside the UTC timestamp, and compute the original local time in their application logic.
6+
7+
#### Example
8+
In the MongoDB shell, you can store both the current date and the current client’s offset from UTC.
9+
10+
```javascript
11+
var now = new Date();
12+
db.data.save( { date: now, offset: now.getTimezoneOffset() } );
13+
```
14+
You can reconstruct the original local time by applying the saved offset:
15+
```javascript
16+
var record = db.data.findOne();
17+
var localNow = new Date( record.date.getTime() - ( record.offset * 60000 ) );
18+
```

0 commit comments

Comments
 (0)