DateTime.Now.toString("yyyyMMdd") depending on CultureInfo?

  • Thread starter Thread starter Frank Hauptlorenz
  • Start date Start date
F

Frank Hauptlorenz

Hi,

I have this instruction mentioned at top running on an japanese client.
Strangely this renders to "200809" (just year and day).

Has anybody an idea?

Thank you,
Frank
 
Hi Frank,

The DateTime.ToString method depends on the CultureInfo.CurrentCulture.

For example, DateTime.Now.ToString("d") will return a string in short date
pattern of the current culture (the "d" is the format character for short
date pattern).

If the CultureInfo.CurrentCulture is the culture of "en-US", the returned
string would be:
"4/16/2008"
If the CultureInfo.CurrentCulture is the culture of "ja-JP", the returned
string would be:
"2008/04/16"

FYI, we can change the current culture using the
Thread.CurrentThread.CurrentCulture property.

Beside the format characters, we can also use format patterns to construct
custom patterns and the format patterns are independent of culture. For
example, the "MM" is a format pattern and it always represents numeric
month.

As for your problem, use the CultureInfo.CurrentCulture property to get the
current culture when running your application. Then execute the following
line of code to see the result it returns:
DateTime.Now.ToString("d")

You may also have a try changing the current culture to another culture,
e.g. en-US, and pass "yyyyMMdd" to the DateTime.ToString method to see if
the problem still exists.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Linda and Peter,

I will try that. I thought "yyyy" renders in every culture to a 4digit
representation.
I've seen resently that not the month gets suppressed but the year:
2008-04-09 renders in Japan to 200409 (with "yyyyMMdd").

Thank you,
Frank
 
Back
Top