When using dynamic/JObject the Json date will be automcatily converted to a localized date. Is it possible to turn that off by in appsettings?
curl http://localhost:64233/api/nets/test \
-H 'content-type: application/json; charset=utf-8' \
-d '{
"dateTime": "2017-06-14T09:20:22+0000"
}'
[HttpPost("test")]
public async Task<dynamic> TestAsync([FromBody] dynamic request)
{
String dateTime = request.dateTime; <--- dateTime "06/14/2017 11:20:22"
...
asked Jun 14, 2017 at 12:33
1 Answer 1
You can change how JSON
serialization handles times zones in your Startup
class by configuring AddJsonOptions
in ConfigureServices
method.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
});
}
answered Jun 14, 2017 at 14:40