What is the correct format to use for Date/Time in an XML file

前端 未结 5 1092
温柔的废话
温柔的废话 2020-11-27 15:50

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?

5条回答
  •  执念已碎
    2020-11-27 16:30

    EDIT: This is bad advice. Use "o", as above. "s" does the wrong thing.

    I always use this:

    dateTime.ToUniversalTime().ToString("s");
    

    This is correct if your schema looks like this:

    
    

    Which would result in:

    2002-05-30T09:00:00
    

    You can get more information here: http://www.w3schools.com/xml/schema_dtypes_date.asp

提交回复
热议问题