2017-06-14 49 views
0

使用動態/ JObject時,Json日期將自動轉換爲本地化日期。在appsettings中可以關閉它嗎?ASP net net datetime往返無JsonSerializationSettings

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" 
... 

回答

1

,您可以更改JSON系列化由ConfigureServices方法配置AddJsonOptions處理您的Startup級次區域。

public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddMvc().AddJsonOptions(options => 
    { 
     options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc; 
    }); 
}