You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Blazor: DateTime.ToString("o") and JsonSerializer.Serialize(DateTime) has a different result in wasm runtime #54343
For local DateTime values which are smaller than 1900-12-31 23:59:17, System.Text.Json.JsonSerializer.Serialize(DateTime) has a different result in wasm runtime(+08:05 vs +08:00).
changed the title [-]Blazor: System.Text.Json.JsonSerializer.Serialize(DateTime) has a different result in wasm runtime [/-][+]Blazor: JsonSerializer.Serialize(DateTime) has a different result in wasm runtime [/+]on Jun 17, 2021
changed the title [-]Blazor: JsonSerializer.Serialize(DateTime) has a different result in wasm runtime [/-][+]Blazor: DateTime.ToString("o") and JsonSerializer.Serialize(DateTime) has a different result in wasm runtime [/+]on Jun 17, 2021
This is likely to do with the history of your local timezone. In the late 1800s it wasn't uncommon for certain regions to run both "Railroad time" (which was agreed-upon throughout the country) and "Local time" (which was different between towns/cities, and therefor could be off by a few minutes relative to Railroad time). The key thing to realize here is that at some point in time, the decision has been made to switch every city/town to "Railroad time" so that it'd all be in sync.
Evidently, the timezone data that is consulted for the conversion believes that 1900-12-31 23:59:17 is the moment when that switch happened for your zone.
System.Text.Json uses the Utf8Formatter class when serializing date values. I would assume there are semantic differences between that implementation and DateTime.ToString("o") in the case of wasm.
Activity
[-]Blazor: System.Text.Json.JsonSerializer.Serialize(DateTime) has a different result in wasm runtime [/-][+]Blazor: JsonSerializer.Serialize(DateTime) has a different result in wasm runtime [/+][-]Blazor: JsonSerializer.Serialize(DateTime) has a different result in wasm runtime [/-][+]Blazor: DateTime.ToString("o") and JsonSerializer.Serialize(DateTime) has a different result in wasm runtime [/+]Joe4evr commentedon Jun 18, 2021
This is likely to do with the history of your local timezone. In the late 1800s it wasn't uncommon for certain regions to run both "Railroad time" (which was agreed-upon throughout the country) and "Local time" (which was different between towns/cities, and therefor could be off by a few minutes relative to Railroad time). The key thing to realize here is that at some point in time, the decision has been made to switch every city/town to "Railroad time" so that it'd all be in sync.
Evidently, the timezone data that is consulted for the conversion believes that
1900-12-31 23:59:17is the moment when that switch happened for your zone.anranruye commentedon Jun 18, 2021
@Joe4evr Thank you.
anranruye commentedon Jun 18, 2021
Now I understand why this happened. However, this makes difference between .Net implements. We still want the same behavior in all .Net implements.
eiriktsarpalis commentedon Oct 15, 2021
System.Text.Json uses the
Utf8Formatterclass when serializing date values. I would assume there are semantic differences between that implementation andDateTime.ToString("o")in the case of wasm.