0

I am using Json.Net's dynamic JSON parsing functionality:

JObject.Parse(jsonString);

I am running into an issue where time information in my raw data is being converted into local time zone. For example

My Raw Json Data:

"scheduledTime": "2015-05-27T10:30:00.000+0000"

My parsed data shows

05/27/2015 03:30:00

which makes sense since my time zone is PST which is 7 hours behind UTC.

I want to prevent Json.Net from performing this conversion from UTC to local time zone, and noticed it is possible to do this via JsonSerializerSettings. However, it seems JObject.Parse() doesn't accept JsonSeralizeSettings.

How do I tell Json.Net to not preform the automatic conversion to local time zone in this case, or I am stuck with having to convert the time zone back to UTC on my own?

Bojin Li
  • 5,769
  • 2
  • 24
  • 37
  • It's not doing any automatic time zone conversion. The value you have is a `DateTime` value. When you look at it in the debugger or the immediate window or whatever, it's showing you the default format, which is in your local time zone. You can do `ToString("s")` on the value to see that it's the same value (or near enough: it will likely have `"Z"` instead of `"+0000"`). The real question is how are you using the value after parsing? – Heretic Monkey Sep 06 '16 at 21:57
  • 2
    You can use `JsonConvert.DeserializeObject()` to use specific settings when parsing JSON to a `JObject`. See [here](https://stackoverflow.com/questions/35138346/jtoken-get-raw-original-json-value/35141787#35141787) for example – dbc Sep 06 '16 at 22:51
  • Thanks dbc, this was exactly what I needed. – Bojin Li Sep 07 '16 at 00:15

0 Answers0