开发者

HowTo: obtain culture dateTime format

开发者 https://www.devze.com 2022-12-26 06:31 出处:网络
?string.Format(CultureInfo.GetCultureInfo(\"en-US\"), \"{0:d}\", now) \"4/12/2010\" ?string.Format(CultureInfo.GetCultureInfo(\"fr-FR\"), \"{0:d}\", now)
?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

精彩评论

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