asp.net core 生成的json 日期格式数据中出现 utc 或 T

1.首先 ,nuget 引入检索 Newtonsoft.Json 包 并安装

using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

2. 在startup 文件 ConfigureServices 方法中 添加

  红色字体代码

 1 public void ConfigureServices(IServiceCollection services)
 2         {
 3             DB.DB_ConnectionString = Configuration.GetConnectionString("mySqlStr");
 4             DB.DB_SqlserverConnectionString = Configuration.GetConnectionString("SqlServerStr"); //SqlServerStr
 5             services.registerService();
 6 
 7               services.AddMvc().AddNewtonsoftJson(options =>
 8             {
 9                 options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
10                 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm";
11 
12 
13                 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
14                 //不使用驼峰样式的key
15                 options.SerializerSettings.ContractResolver = new DefaultContractResolver();
16                 //设置时间格式
17                 //options.SerializerSettings.DateFormatString = "yyyy-MM-dd";
18             });
19 
20 
21         }

 

3.添加以上代码后  controller中 在生产json数据 日期格式 即可恢复正常 

 

posted on 2021-10-01 17:16  码农at突泉  阅读(306)  评论(0)    收藏  举报