不同的DateTimeFormat用于开发和测试环境

不同的DateTimeFormat用于开发和测试环境

本文介绍了不同的DateTimeFormat用于开发和测试环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET MVC项目的global.asax.cs的的Application_BeginRequest()方法中有code:

In the Application_BeginRequest() method of global.asax.cs in my ASP.NET MVC project there is code:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(EnCultureKey);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(EnCultureKey);
Thread.CurrentThread.CurrentCulture.DateTimeFormat = new CultureInfo(EnGBCultureKey).DateTimeFormat;

变量是

private const string EnCultureKey = "en-US";
private const string EnGBCultureKey = "en-GB";

在开发环境中的所有日期是在DD / MM / YYYY格式,但在测试环境中,他们都在MM / DD / YYYY格式。

On the dev environment all the dates are in DD/MM/YYYY format, but on the test environment they are in MM/DD/YYYY format.

请你在什么可能是这种差异的原因告诉我?

Could You please advise me on what could be the cause of this difference?

更新:

请看看

推荐答案

如果你想覆盖所有网页这些设置(而不是给用户一个选择),那么标准方法是的:

If you do want to override these settings for all your pages (instead of giving the User a choice) then the standard way is a setting in web.config :

  <globalization uiCulture="en" culture="en-GB" />

在MSDN网页还指出你覆盖 InitializeCulture()如果你想使用code。

The MSDN page also points you to overriding InitializeCulture() if you want to use code.

InitializeCulture()早发生,但我怀疑的Application_BeginRequest甚至更早发生,其影响覆盖。

InitializeCulture() happens early but I suspect that Application_BeginRequest happens even earlier and that its effects are overridden.

这篇关于不同的DateTimeFormat用于开发和测试环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:04