'c# - Get Datetime local format
When I post a datetime value to my web API I get different results and I want to get datetime in local format
MyViewModel :
public class MyViewModel
{
public DateTime Time { get; set; }
}
I post json like this
{ "Time": "2020-09-08T04:00:00.000Z" }
to api/Values
[RoutePrefix("api/Values")]
public class ValuesController: ApiController
{
// POST api/values
public object Post(MyViewModel model)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(model);
}
}
the result in the same format is UTC
{\"Time\": \"2020-09-08T04:00:00Z\"}
But when I post the same Json to HomeController
public class HomeController: Controller
{
public object Post(MyViewModel model)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(model);
}
}
the result is in local format like this
{ "Time":"2020-09-08T07:00:00+03:00" }
I want result to be in local format like HomeController
How can i implement it ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
