不同DateTimeFormat在不同的机器相同的培养 [英] Different DateTimeFormat for the same culture in different machines
问题描述
我有一个问题,当我部署不同的服务器上我的Web应用程序。似乎有一些 DateTimeFormat
模式不一致,如 ShortDatePattern
,使用相同的文化(PT-BR)。
I'm having a problem when I deploy my web application in different servers. There seems to be an inconsistency in some DateTimeFormat
patterns, like ShortDatePattern
, using the same culture (pt-BR).
在我的机器(Windows 7中安装了.NET 4,应用针对.NET 3.5),并在Windows Server 2008 R2(与应用程序面向.NET 4)服务器ShortDatePattern是DD / MM / YYYY
- 这是正确的,我猜
In my development machine (Windows 7, .NET 4 installed, application targeting .NET 3.5) and a Windows Server 2008 R2 (with the application targeting .NET 4) server the ShortDatePattern is "dd/MM/yyyy"
- which is the correct, I guess.
在生产服务器(Windows Server 2003中,使用.net 3.5),这是D / M / YYYY
。这是害我吨的麻烦。
In the production server (Windows Server 2003, using .NET 3.5) it is "d/M/yyyy"
. It is causing me tons of trouble.
我可以通过手动设置模式解决了问题,但我真的很想避免这样做,我需要输出的日期每次。特别因为这会在很多地方(比如,我使用MVC的Html.TextBoxFor),并需要重写一个良好的数额不平凡的。
I could solve the issue by setting the patterns by hand, but I'd really like to avoid doing this every time I need to output a date. Specially since this will be non-trivial in many places (like where I use MVC's Html.TextBoxFor) and will require a good amount of rewriting.
如果有改变的模式在一个地方整个Web应用程序这将是巨大的一种方式。我试着在的Global.asax.cs
文件中的以下方法,没有成功:
If there's a way of changing the patterns for the entire web application in one place it would be great. I've tried the following approach in the Global.asax.cs
file, with no success:
CultureInfo info = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
info.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
System.Threading.Thread.CurrentThread.CurrentCulture = info;
任何想法?
感谢您。
推荐答案
其实,我是想在Global.asax文件中错误的地方使用code以上。
Actually, I was trying to use the code above in the wrong place in the Global.asax file.
我设法把code在的Application_BeginRequest方法来覆盖整个aplication的ShortDatePattern:
I managed to override the ShortDatePattern for the entire aplication by putting the code in the Application_BeginRequest method:
protected void Application_BeginRequest()
{
CultureInfo info = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
info.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
System.Threading.Thread.CurrentThread.CurrentCulture = info;
}
这篇关于不同DateTimeFormat在不同的机器相同的培养的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!