HowTo: obtain culture dateTime format
?string.Format(CultureInfo.GetCultureInfo("en-US"), "{0:d}", now)
"4/12/2010"
?string.Format(CultureInfo.GetCultureInfo("fr-FR"), "{0:d}", now)
"12/04/2010"
I want to write a method: string GetDateFormat(culture)
?GetDateFormat(CultureInfo.GetCultureInfo("en-US"))
"M/d/yyyy"
?GetDateFormat(CultureInfo.GetCultureInfo("fr-FR"))
"dd/M开发者_JAVA技巧M/yyyy"
Is it possible?
You may take a look at the ShortDatePattern property:
CultureInfo.GetCultureInfo("en-US").DateTimeFormat.ShortDatePattern
The more general purpose answer is to use GetAllDateTimePatterns:
CultureInfo.GetCultureInfo("en-US").DateTimeFormat.GetAllDateTimePatterns('d')[0]
Note that GetCultureInfo will not pick up any user overrides.
精彩评论