且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用DataContractJsonSerializer的自定义DateTime序列化/反序列化

更新时间:2022-06-22 08:55:07

我可能遗漏了一些东西,但是在创建序列化程序时尝试在设置中传递所需的日期和时间格式:

I might be missing something, but try passing the desired date and time format in the settings when creating the serializer:

var serializer = new DataContractJsonSerializer(
    typeof(Client),
    new DataContractJsonSerializerSettings {
        DateTimeFormat = new DateTimeFormat("yyyy-MM-dd hh:mm:ss"),
    });