【发布时间】:2011-03-31 20:02:04
【问题描述】:
我在不同服务器上部署 Web 应用程序时遇到问题。使用相同文化 (pt-BR) 的某些 DateTimeFormat 模式(例如 ShortDatePattern)似乎存在不一致。
在我的开发机器(安装了 Windows 7,.NET 4,应用程序面向 .NET 3.5)和 Windows Server 2008 R2(应用程序面向 .NET 4)服务器中,ShortDatePattern 是 "dd/MM/yyyy" - 这是正确的,我猜。
在生产服务器(Windows Server 2003,使用 .NET 3.5)中,它是"d/M/yyyy"。它给我带来了很多麻烦。
我可以通过手动设置模式来解决这个问题,但我真的很想避免每次需要输出日期时都这样做。特别是因为这在很多地方(比如我使用 MVC 的 Html.TextBoxFor 的地方)都是不平凡的,并且需要大量的重写。
如果有一种方法可以在一个地方更改整个 Web 应用程序的模式,那就太好了。我在Global.asax.cs 文件中尝试了以下方法,但没有成功:
CultureInfo info = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
info.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
System.Threading.Thread.CurrentThread.CurrentCulture = info;
有什么想法吗?
谢谢。
【问题讨论】:
标签: asp.net datetime cultureinfo