2

i am in a zone where the local time is GMT +6. now how can i get the appropriate time from a json time string accroding to my zone. i tried the following approach but it returns a date with a day off(one day previous date).

public ActionResult DateParser(string date)
{
    string sDate = WrapStringInQuotes(date);
    DateTime dt = JsonConvert.DeserializeObject<DateTime>(sDate); // the dt i want have to be gmt +6
}
public string WrapStringInQuotes(string input)
{
    return @"""" + input + @"""";
}

I tried for help here but didn't understand how can i get the appropriate date.

While i convert the json string date Here it decoded the date as per as my time zone.

1 Answers1

1

You can use JsonSerializerSettings to control how the date is processed like:

var jsonSerializerSettings = new JsonSerializerSettings()
{
     DateTimeZoneHandling = DateTimeZoneHandling.Local
};

var obj = JsonConvert.DeserializeObject<DateTime>(sDate, jsonSerializerSettings);
Alex Riabov
  • 8,655
  • 5
  • 47
  • 48