1

Edit: Solved, duplicate: Prevent timezone conversion on deserialization of DateTime value


I've come across a strange bug when trying to deserialize the 30th Sept 2000.

2000-09-30T00:00:00+11:00 turns the date into 29/09/2000 11:00:00 PM.

How can I prevent it losing a day in the conversion:

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
 }
}
Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321

1 Answers1

2

The XML presentation of this date is for the UTC +11 timezone, see http://www.timeanddate.com/time/map/

So, when it is 12 at midnight the 30th in UTC +11 timezone, it is 11 PM the 29th in Sydney (UTC + 10) :-)

GTG
  • 4,914
  • 2
  • 23
  • 27