[CSHARP-2871] DateTime serializes with one hour offset Created: 10/Dec/19 Updated: 27/Oct/23 Resolved: 20/Dec/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON, Serialization |
| Affects Version/s: | 2.9.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Samir Kharchi | Assignee: | Dmitry Lukyanov (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Win10, Local MongoDB server |
||
| Description |
|
I have a DateTime property in my class which is set to a date but no time, e.g. Dec 7, 1980 0:00:00. {{public DateTime DateOfBirth { get; set; }}} The property is auto serialized (no bson attributes or whatever) and the expected value in the collection is: 1980-12-07T00:00:00.000+00:00 However what is written to the database instead is: 1980-12-06T23:00:00.000+00:00
|
| Comments |
| Comment by Samir Kharchi [ 19/Dec/19 ] |
|
Hi dmitry.lukyanov, thank you for your answer. That clears it up! |
| Comment by Dmitry Lukyanov (Inactive) [ 17/Dec/19 ] |
|
Hello skharchi@xion-medical.com, it happens because we convert dates to universal time(UTC) during serialization. So, if you need converting to local time zones, you should do it in your code. Let me know if you have any questions. |