I have a date serialized as a string "2012-06-20T13:19:59.1091122Z"
Using the DateTimeConverter, this gets converted to a DateTime object {22:49:59.1091122} with the Kind property set to "Local".
eg. The following test fails:
private static readonly DateTime UtcDate = new DateTime(634757951991091122, DateTimeKind.Utc);
private const string UtcSerialisedDate = "2012-06-20T13:19:59.1091122Z";
[Test]
public void DateTimeConverter_Convert_From_Utc_String()
{
// Arrange
var converter = TypeDescriptor.GetConverter(typeof(DateTime));
// Act
var result = converter.ConvertFrom(UtcSerialisedDate);
// Assert
Assert.AreEqual(UtcDate, result);
Assert.AreEqual(DateTimeKind.Utc, ((DateTime)result).Kind);
}
I'm a bit surprised by this... I would have expected that the DateTime object returned by the converter would be in UTC.
The docs do say that DateTimeConverter uses DateTime.Parse, but I'm guessing it must not use the DateTimeStyles.RoundtripKind option.
Is there any way around this?