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

查看:1839
本文介绍了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日期格式。这是首选格式和标准日期和时间格式字符串,虽然如果您不希望使用以下格式的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 Service生成的类,可以直接将DateTime实例分配给类属性。如果您正在编写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天全站免登陆