[英]How does WCF DataContractJsonSerializer deserialize a json DateTime?
I have 2 datetime json strings, the only difference is the offset part, one is -08, the other one is -09:我有2个日期时间json字符串,唯一的区别是偏移部分,一个是-08,另一个是-09:
"/Date(946713600000-0800)/"
"/Date(946713600000-0900)/"
When I deserialize them using DataContractJsonSerializer当我使用 DataContractJsonSerializer 反序列化它们时
var serializer = new DataContractJsonSerializer(typeof(DateTime));
byte[] byteArray1 = Encoding.UTF8.GetBytes("\"\\/Date(946713600000-0800)\\/\"");
MemoryStream stream1 = new MemoryStream(byteArray1);
var datetime1 = serializer.ReadObject(stream1 );
byte[] byteArray2 = Encoding.UTF8.GetBytes("\"\\/Date(946713600000-0900)\\/\"");
MemoryStream stream2 = new MemoryStream(byteArray2);
var datetime2 = serializer.ReadObject(stream2 );
The result supersize me, datetime1 and datetime2 are exactly the same!结果supersize me,datetime1和datetime2一模一样! both are {1/1/2000 12:00:00 AM}, datetime1.Kind and datetime2.Kind are both Local.
两者都是 {1/1/2000 12:00:00 AM},datetime1.Kind 和 datetime2.Kind 都是本地的。
I expect they have one hour difference.我希望他们有一个小时的差异。 Why they are same?
为什么他们是一样的?
The time portion is the same value between the two dates.时间部分是两个日期之间的相同值。 The offset, represented as -0900 and -0800, in your example, is just extra information that denotes the offset from UTC that the local time was captured in.
在您的示例中,表示为 -0900 和 -0800 的偏移量只是额外信息,表示捕获本地时间的 UTC 偏移量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.