Does DateTime.ToString ("s") return the same format?

According to MSDN in DateTime.ToString ToString ("s") should always return a string in the style formatting format of the sortable XML schema, for example: 2008-10-01T17: 04: 32.0000000

In Reflector, I came to this template inside DateTimeFormatInfo.

public string SortableDateTimePattern
{
      get
      {
            return "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
      }
}

Does DateTime.ToString ("s") return a string in this format?
Regardless of culture, region, ...


Yes, he makes a code to verify that

var dateTime = DateTime.Now;
var originialString = dateTime.ToString("s");
string testString;

foreach (var c in System.Globalization.CultureInfo.GetCultures(CultureTypes.AllCultures))
{
    Thread.CurrentThread.CurrentUICulture = c;
    if (c.IsNeutralCulture == false)
    {
        Thread.CurrentThread.CurrentCulture = c;
    }

    testString = dateTime.ToString("s");
    Console.WriteLine("{0} ", testString);
    if (originialString != testString)
    {
        throw new ApplicationException(string.Format("ToString(s) is returning something different for {0} " , c));
    }
}
+5
source share
2 answers

, . , (, "T" ":" ), .

+14

. , , - .

yyyy - 4-
- 2-
dd - 2-
T - T
HH - 2- , 24-
-
ss - ,

+11

All Articles