Newtonsoft.json: DateTimeOffset losing source timezone information on deserialization

Created on 26 Sep 2012  路  2Comments  路  Source: JamesNK/Newtonsoft.Json

I'm using json.net to deserialize a datetimeoffset, but it is ignoring the specified timezone and converting the datetime to the local offset. For example, given

var content = @"{""startDateTime"":""2012-07-19T14:30:00+09:30""}";

When deserialized using:
var jsonSerializerSettings = new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.IsoDateFormat, DateParseHandling = DateParseHandling.DateTimeOffset, DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind };
var obj = JsonConvert.DeserializeObject(content, jsonSerializerSettings);

The obj will contain a property containing a DateTimeOffset but the value will be 2012-07-19T15:30:00+10:30 i.e. converted to the local timezone instead of preserving the original timezone.

Is there a way to get the value to be parsed as expected so that the resulting DateTimeOffset property will match the supplied value?

Most helpful comment

I'm busy getting this exact bug.

All 2 comments

That's a bug. Fixed!

I'm busy getting this exact bug.

Was this page helpful?
0 / 5 - 0 ratings