您可以为日期时间的 XmlSerialization 指定格式吗? [英] Can you specify format for XmlSerialization of a datetime?

查看:28
本文介绍了您可以为日期时间的 XmlSerialization 指定格式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将日期时间序列化/反序列化为 XML 文件的 yyyyMMdd 格式.是否有我可以使用的属性/解决方法?

I need to serialize / deserialize a datetime into yyyyMMdd format for an XML file. Is there an attribute / workaround I can use for this?

推荐答案

不,没有.如果它是那种格式,那么就 XML 架构而言,它不是有效的日期时间.

No, there isn't. If it's in that format, then it's not a valid dateTime as far as XML Schema is concerned.

你能做的最好的事情如下:

The best you can do is as follows:

[XmlIgnore]
public DateTime DoNotSerialize {get;set;}

public string ProxyDateTime {
    get {return DoNotSerialize.ToString("yyyyMMdd");}
    set {DoNotSerialize = DateTime.Parse(value);}
}

这篇关于您可以为日期时间的 XmlSerialization 指定格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆