开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜