在C#中反序列化JSON日期的问题-增加2小时 [英] Problem deserializating JSON Date in C# - adding 2 hours
本文介绍了在C#中反序列化JSON日期的问题-增加2小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在将JSON日期反序列化为C#DateTime时,我们遇到了一个令人讨厌的问题.
We are having such a nasty problem when deserializating a JSON date to a C# DateTime.
代码是:
JavaScriptSerializer serializer = new JavaScriptSerializer();
jsonTrechos = jsonTrechos.Replace("/Date(", "\\/Date(").Replace(")/", ")\\/");
Trecho[] model = serializer.Deserialize<Trecho[]>(jsonTrechos);
jsonTrechos
是json2.js的JSON.stringify();
的字符串.
The jsonTrechos
is a string of json2.js's JSON.stringify();
.
问题是:反序列化的工作原理是,将Trechos对象的所有日期都添加2小时.
Problem is: the deserialization works, bur all dates of the Trechos objects are added with 2 hours.
我的时区是巴西(UTC -3),并且我们有夏令时(因此我们目前使用的是UTC -2).我想也许本地化和时区可能在其中起作用,如果确实如此,我不知道如何解决.
My timezone is Brazil (UTC -3) and we're under daylight savings (so we're currently on UTC -2), if it has anything to do. I guess that perhaps localization and timezones may be playing a part on this and if they really are, I have no idea on how to fix it.
推荐答案
查看全文