469,898 Members | 1,772 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

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

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 Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Sep 1 '06 #1
4 14033
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_comschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
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 Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )

Sep 2 '06 #2
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 Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Sep 3 '06 #3
Greg Collins [Microsoft MVP] wrote:
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
Sep 3 '06 #4
Great! Thanks for all your replies.

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Sep 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Al Reid | last post: by
1 post views Thread by Marc Gravell | last post: by
2 posts views Thread by =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.