0

when I read data value it changed. i need this string value 2018-03-27T20:00:00+11:00 but getting 3/27/2018 2:00:00 PM in mydate string.

 static void Main(string[] args)
    {
        string data="{\"start_date\":\"2018-03-27T20:00:00+11:00\",\"end_date\":null,\"on_sale_date\":\"2017-11-24T08:55:00+11:00\",\"date_confirmed\":true}";
        JObject pdata = JObject.Parse(data);
        string mydate = pdata["start_date"].ToString();

    }
sara
  • 3
  • 1
  • 1
    Due to timezone differences? – Sunil Jan 11 '18 at 12:13
  • Possible duplicate of [How to preserve timezone when deserializing DateTime using JSON.NET?](https://stackoverflow.com/questions/27043220/how-to-preserve-timezone-when-deserializing-datetime-using-json-net) – less Jan 11 '18 at 12:32

1 Answers1

1

I think it is not possible to disable the DateParseHandling with JObject.Parse.
You can use the DeserializeObject methode from JsonConvert and disable the DateParseHandling:

string data = "{\"start_date\":\"2018-03-27T20:00:00+11:00\",\"end_date\":null,\"on_sale_date\":\"2017-11-24T08:55:00+11:00\",\"date_confirmed\":true}";
dynamic pdata = JsonConvert.DeserializeObject(data, new JsonSerializerSettings()
{
    DateParseHandling = DateParseHandling.None
});
string mydate = pdata.start_date;
Console.WriteLine(mydate);
PinBack
  • 2,499
  • 12
  • 16