gpt4 book ai didi

.net-core - 如何为.net core 2.0 webapi设置默认日期时间格式

转载 作者:行者123 更新时间:2023-12-02 23:17:22 25 4
gpt4 key购买 nike

目前在我本地。 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com