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.

asked Jul 12, 2018 at 9:05
2
  • 1
    What is your json date format? Commented Jul 12, 2018 at 9:13
  • its something like /Date(1531332000000). i can deserialize the date but it is one day behind Commented Jul 12, 2018 at 9:15

1 Answer 1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.