什么是在一个XML文件中使用的日期/时间格式正确 [英] What is the correct format to use for Date/Time in an XML file

查看:854
本文介绍了什么是在一个XML文件中使用的日期/时间格式正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不要使用.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.

这篇关于什么是在一个XML文件中使用的日期/时间格式正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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