什么是在一个XML文件中使用的日期/时间格式正确是在、正确、日期、格式

由网友(小情绪反反复复作祟^)分享简介:不要使用.NET编写到一个XML文件,当我使用的日期/时间是什么格式?难道我只是使用则DateTime.ToString(),还是必须要使用特定的格式?What format do I use for Date/Time when writing to an XML file using .NET? Do I sim...

不要使用.NET编写到一个XML文件,当我使用的日期/时间是什么格式?难道我只是使用则DateTime.ToString(),还是必须要使用特定的格式?

What format do I use for Date/Time when writing to an XML file using .NET? Do I simply use DateTime.ToString(), or do I have to use a specific format?

推荐答案

我一直使用 ISO 8601 的格式,例如: 2008-10-31T15:07:38.6875000-05:00 - 与Date.toString(O)。这是 XSD日期格式的为好。这是preferred格式和标准日期和时间格式字符串,虽然可以使用手动格式字符串,如果必要的,如果你不想在格式的T:与Date.toString(YYYY-MM-DD HH:MM:SS);

I always use the ISO 8601 format, e.g. 2008-10-31T15:07:38.6875000-05:00 -- date.ToString("o"). It is the XSD date format as well. That is the preferred format and a Standard Date and Time Format string, although you can use a manual format string if necessary if you don't want the 'T' in the format: date.ToString("yyyy-MM-dd HH:mm:ss");

编辑:如果您是从XSD或Web服务使用生成的类,你可以直接指定日期时间实例的类属性。如果你正在写XML文本,然后使用以上。

If you are using a generated class from an XSD or Web Service, you can just assign the DateTime instance directly to the class property. If you are writing XML text, then use the above.

阅读全文

相关推荐

最新文章