none
C# and ISO 8601?

    Question

  • I am being asked to take a date and encode it to something that conforms to ISO 8601. I've seen some references to a possible C# "DateTime" object that may be capable of doing so. Does anyone know more about this? For instance how would I encode "Jan 1, 2012" to ISO 8601?
    Tuesday, March 20, 2012 8:09 PM

Answers

  • You can output the datetime in any format you want. 

    Here you can find many possible formats and through that it should be easier for you to make your preferd output format:

    http://www.csharp-examples.net/string-format-datetime/

    • Marked as answer by S.e.p.y Tuesday, March 20, 2012 8:45 PM
    Tuesday, March 20, 2012 8:32 PM
  • Wikipedia answer for what 8601 is:

    Calendar dates
    YYYY-MM-DD or YYYYMMDD
    YYYY-MM (but not YYYYMM)

    Calendar date representations are in the form as shown in the box to the right. [YYYY] indicates a four-digit year, 0000 through 9999. [MM] indicates a two-digit month of the year, 01 through 12. [DD] indicates a two-digit day of that month, 01 through 31. For example, "the 5th of April 1981" may be represented as either "1981-04-05" in the extended format or "19810405" in the basic format.

    The standard also allows for calendar dates to be written with reduced precision. For example, one may write "1981-04" to mean "1981 April", and one may simply write "1981" to refer to that year or "19" to refer to the century from 1900 to 1999 inclusive.

    Although the standard allows both the YYYY-MM-DD and YYYYMMDD formats for complete calendar date representations, if the day [DD] is omitted then only the YYYY-MM format is allowed. By disallowing dates of the form YYYYMM, the standard avoids confusion with the truncated representation YYMMDD (still often used).

    Link to the custom date format strings: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

    Have fun and let us know if you have issues figuring out a specific format.


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    Tuesday, March 20, 2012 8:35 PM

All replies

  • You can output the datetime in any format you want. 

    Here you can find many possible formats and through that it should be easier for you to make your preferd output format:

    http://www.csharp-examples.net/string-format-datetime/

    • Marked as answer by S.e.p.y Tuesday, March 20, 2012 8:45 PM
    Tuesday, March 20, 2012 8:32 PM
  • Wikipedia answer for what 8601 is:

    Calendar dates
    YYYY-MM-DD or YYYYMMDD
    YYYY-MM (but not YYYYMM)

    Calendar date representations are in the form as shown in the box to the right. [YYYY] indicates a four-digit year, 0000 through 9999. [MM] indicates a two-digit month of the year, 01 through 12. [DD] indicates a two-digit day of that month, 01 through 31. For example, "the 5th of April 1981" may be represented as either "1981-04-05" in the extended format or "19810405" in the basic format.

    The standard also allows for calendar dates to be written with reduced precision. For example, one may write "1981-04" to mean "1981 April", and one may simply write "1981" to refer to that year or "19" to refer to the century from 1900 to 1999 inclusive.

    Although the standard allows both the YYYY-MM-DD and YYYYMMDD formats for complete calendar date representations, if the day [DD] is omitted then only the YYYY-MM format is allowed. By disallowing dates of the form YYYYMM, the standard avoids confusion with the truncated representation YYMMDD (still often used).

    Link to the custom date format strings: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

    Have fun and let us know if you have issues figuring out a specific format.


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    Tuesday, March 20, 2012 8:35 PM
  • ISO 8601 is one of the standard formats. http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#Sortable

    You don't need to look up the pattern. Use mydate.ToString("s")

    Wednesday, March 21, 2012 8:23 AM