ICR*_*ICR 17 .net globalization date internationalization
本地化日期格式描述符的最佳方法是什么?
任何来自不使用mm/dd/yyyy格式的文化的人都知道,必须以这种格式输入日期是很烦人的..NET框架提供了一些非常好的本地化支持,因此根据用户文化解析日期是微不足道的,但是您通常还希望显示有关所需格式的有用提示(尤其是区分yy和yyyy,它们可以互换)大多数文化).
以对大多数用户有意义的方式执行此操作的最佳方式是什么(例如,由于案例的变化以及一到两个字母之间的切换,dd/M/yyy会让人感到困惑).
只需使用ISO-8601.这是一个国际标准.
Date and time (current at page generation) expressed according to ISO 8601:
Date: 2014-07-05
Combined date and time in UTC: 2014-07-05T04:00:25+00:00
2014-07-05T04:00:25Z
Week: 2014-W27
Date with week number: 2014-W27-6
Ordinal date: 2014-186
Run Code Online (Sandbox Code Playgroud)
这是我目前的方法。有什么建议么?
Regex singleMToDoubleRegex = new Regex("(?<!m)m(?!m)");
Regex singleDToDoubleRegex = new Regex("(?<!d)d(?!d)");
CultureInfo currentCulture = CultureInfo.CurrentUICulture;
// If the culture is netural there is no date pattern to use, so use the default.
if (currentCulture.IsNeutralCulture)
{
currentCulture = CultureInfo.InvariantCulture;
}
// Massage the format into a more general user friendly form.
string shortDatePattern = CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern.ToLower();
shortDatePattern = singleMToDoubleRegex.Replace(shortDatePattern, "mm");
shortDatePattern = singleDToDoubleRegex.Replace(shortDatePattern, "dd");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
693 次 |
| 最近记录: |