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

查看:137
本文介绍了您可以为日期时间的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 Schema而言,它不是有效的dateTime。

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天全站免登陆