Format always consistent for DateTime.ToString("s") ?

  • Thread starter Thread starter Greg Collins [Microsoft MVP]
  • Start date Start date
G

Greg Collins [Microsoft MVP]

Will DateTime.Now.ToString("s") ALWAYS return the same formatting (i.e. the sortable XML Schema style formatting) regardless of what culture the operating system is set to?

I've done limited testing to show that this is the case when switching to the Italian culture, but I need to verify that in EVERY culture setting it will ALWAYS return the same format.

Thanks.
 
Greg,

Iso date notation is ISO, why would it give another format in Italy than in
the USA.
The base is exact the same and the result should be exact the same.
(Should be because I am not aware of bugs).

yyyy MM dd hh mm ss

Cor



"Greg Collins [Microsoft MVP]" <gcollins_AT_msn_DOT_com> schreef in bericht
Will DateTime.Now.ToString("s") ALWAYS return the same formatting (i.e. the
sortable XML Schema style formatting) regardless of what culture the
operating system is set to?

I've done limited testing to show that this is the case when switching to
the Italian culture, but I need to verify that in EVERY culture setting it
will ALWAYS return the same format.

Thanks.
 
Sorry, I should have been a little more clear...

When I use, for example, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"); when the operating system is set to another culture (in this example, Italian), .NET converts that formatting to the locale-specific format, and I get the time using dots instead of colons: "yyyy-MM-ddTHH.mm.ss".

Now note that I did not specify that I wanted the formatting to be using the en-US culture info.

But I also noticed that .ToString("s"), even when in the Italian culture, properly gives me the colons in the time formatting. This is essential for working with XML to avoid schema validation errors.

So my question is whether using "s", no matter what culutre the operating system is set to, will ALWAYS give the same formatting: "yyyy-MM-ddTHH:mm:ss"?

I want to be sure there's not some corner case where it will ever NOT give that same identical formattng.
 
Greg said:
Sorry, I should have been a little more clear...

When I use, for example,
DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"); when the operating
system is set to another culture (in this example, Italian), .NET
converts that formatting to the locale-specific format, and I get the
time using dots instead of colons: "yyyy-MM-ddTHH.mm.ss".

Now note that I did not specify that I wanted the formatting to be
using the en-US culture info.

But I also noticed that .ToString("s"), even when in the Italian
culture, properly gives me the colons in the time formatting. This is
essential for working with XML to avoid schema validation errors.

So my question is whether using "s", no matter what culutre the
operating system is set to, will ALWAYS give the same formatting:
"yyyy-MM-ddTHH:mm:ss"?

I want to be sure there's not some corner case where it will ever NOT
give that same identical formattng.

If there is such a case, it's a bug. The documentation says specifically
that it uses the format string "yyyy-MM-ddTHH:mm:ss" and use the
InvariantCulture, so it'll always be the same, regardless of the current
culture.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top