【发布时间】:2019-01-06 22:28:59
【问题描述】:
我想创建一个自定义的 json 序列化程序,它将带有 dateTime 的对象与 UTC 相互转换,并返回到指定的时区。 (非本地)
转换为 UTC 的示例是:
MyObject stuff = new MyObject();
stuff.Date = DateTime.Now;
string asdd = JsonConvert.SerializeObject(stuff,
new JsonSerializerSettings()
{
DateTimeZoneHandling = DateTimeZoneHandling.Utc
});
如何通过 JsonSerializerSettings 或自定义序列化程序从 UTC 转换回特定时区?
注意:我正在使用 .NET Core 2.1。
【问题讨论】:
标签: c# datetime .net-core timezone jsonserializer