修改:已解决,重复: Prevent timezone conversion on deserialization of DateTime value
我试图在2000年9月30日反序列化时遇到一个奇怪的错误。
2000-09-30T00:00:00 + 11:00将日期改为29/09/2000 11:00:00 PM。
如何防止它在转化中失去一天:
public class Data
{
[XmlArray("Times")]
[XmlArrayItem("Time")]
public List<DateTime> Times { get; set; }
public void Test()
{
XmlReader xr = XmlReader.Create(new StringReader(@"<Data><Times><Time>2000-09-30T00:00:00+11:00</Time><Time>1900-01-01T06:00:00</Time></Times></Data>"));
XmlSerializer ser = new XmlSerializer(typeof(Data));
Data data = (Data)ser.Deserialize(xr);
// hover over data and see date is the 29th
}
}
答案 0 :(得分:2)
此日期的XML演示文稿适用于UTC +11时区,请参阅http://www.timeanddate.com/time/map/
所以,当它在UTC +11时区的30日午夜12点时,悉尼时间是晚上11点(格林威治标准时间+10点): - )