Skip to content

Commit ab4d5d5

Browse files
authored
docs(en): update example
1 parent 614e0b5 commit ab4d5d5

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

docs/en/faq.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
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.
55
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.
66

7-
#### Example
8-
In the MongoDB shell, you can store both the current date and the current client’s offset from UTC.
7+
#### Example for reconstructing the original local time by applying the saved offset:
8+
From the MongoDB shell
99

1010
```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 ) );
11+
var record = db.getCollection("riskScore").findOne()
12+
print(new Date(record.dateTime.getTime() + (record.timeZoneOffset)) )
1813
```

0 commit comments

Comments
 (0)