services.AddMvc().AddJsonOptions(opt =>{ opt.

ASP.NET Core 返回 Json DateTime 格式

来源:这里教程网 时间:2026-02-21 14:50:37 作者:

asp.net core 返回 json 格式的时候,如果返回数据中有

datetime
类型,如何自定义其格式呢?配置如下:

<code class="sourceCode cs">services.<span class="fu">AddMvc</span>().<span class="fu">AddJsonOptions</span>(opt =>
{
    opt.<span class="fu">SerializerSettings</span>.<span class="fu">DateFormatString</span> = <span class="st">"yyyy-MM-dd HH:mm"</span>;
});</code>

参考资料:

Json date being serialized to wrong format

相关推荐