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

标签 .net-core asp.net-core-2.0 asp.net-core-webapi

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

相关文章:

c# - 当我们使用 ASP.NET API Core 2.1 时如何在 MongoDB 中使用多集合进行操作

botframework - 机器人 channel 注册 - 将此消息发送到您的机器人时出错 : HTTP status code Unauthorized

c# - 如何在 .net 核心中散列密码,使其在 .net 框架中相等

asp.net-core-2.0 - 微软.NETCore.App 2.0.3

c# - Auto Mapper Profiler Class 放置在哪个文件夹中?

c# - 如何在 ASP.NET Core Web API 项目中允许使用 IP 地址进行 CORS?

c# - 使用不同的卡结账时,Stripe 正在创建重复的客户

sql-server - SQL Server 实例在登录协商期间返回无效或不受支持的协议(protocol)版本

bash - 如何在 dot.net 核心中运行 bash 命令

.net - 使用路径前缀在生产中运行 asp.net core 应用程序