Rulisp
Rulisp

Reputation: 1736

JArray prevent date parsing

I receive array of dates from server in format

[{"date":"2016-12-26T00:00:00+08:00"}, 
{"date":"2016-12-27T00:00:00+08:00"},
{"date":"2016-12-28T00:00:00+08:00"},
{"date":"2016-12-29T00:00:00+08:00"}]

And I try to parse them with JArray.Parse method. The problem is: method modifies date to Moscow TZ(which is set on my PC). So, after parsing, dates look like this

  "date": "2016-12-25T19:00:00+03:00"
  "date": "2016-12-26T19:00:00+03:00"
  "date": "2016-12-27T19:00:00+03:00"

And the question is: is it possible to prevent date modifying?

Upvotes: 2

Views: 456

Answers (1)

huse.ckr
huse.ckr

Reputation: 530

var s = "['2016-05-10T13:51:20Z', '2016-05-10T13:51:20+00:00']";
using (JsonReader jsonReader = new JsonTextReader(new StringReader(s))) {
 jsonReader.DateParseHandling = DateParseHandling.None;
 var array = JArray.Load(jsonReader);
foreach (var item in array) {
 var itemValue = item.Value<string>();
Console.WriteLine(itemValue);}
}

OUTPUT:

2016-05-10T13:51:20Z
2016-05-10T13:51:20+00:00

Upvotes: 2

Related Questions