目前在我本地。 API 期望的格式与 SQL Server 数据库中的格式相同,即 yyyy-mm-dd。
但是,当我将应用程序部署到生产服务器时。 API 期望日期时间格式为 yyyy-dd-mm。
有没有办法配置我的 .net core Web api 以接受 yyyy-mm-dd 作为每个环境中的默认格式?
最佳答案
请显示一些代码。您可以在 ConfigureServices()
AddJsonOptions()
管道中尝试以下操作
services
.AddMvc()
.AddJsonOptions(options =>
{
//Set date configurations
//options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
options.SerializerSettings.DateFormatString = "yyyy-MM-dd"; // month must be capital. otherwise it gives minutes.
});
关于.net-core - 如何为.net core 2.0 webapi设置默认日期时间格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49976468/