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.
unknownuserunknownuser
-
1What is your json date format?Alex Riabov– Alex Riabov2018年07月12日 09:13:44 +00:00Commented Jul 12, 2018 at 9:13
-
its something like /Date(1531332000000). i can deserialize the date but it is one day behindunknownuser– unknownuser2018年07月12日 09:15:54 +00:00Commented Jul 12, 2018 at 9:15
1 Answer 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);
answered Jul 12, 2018 at 9:31
Comments
Explore related questions
See similar questions with these tags.
default