当前文化和操作系统日期配置
我在这里有一个非常棘手的问题。我已经在这个问题上低下头好几个小时了,但没有成功。
我正在构建一个要部署在具有不同文化的众多机器上的应用程序。 作为预防措施,我决定使用 Culture 类来帮助在字符串和日期之间进行转换。 我注意到,当我将 Windows 操作系统日期从
10/07/2011 更改为 10-07-2011 时,
CurrentCulture 没有更新,我一直看到日期为 10/07/2011。 这是为什么?有什么解决方法吗?
I have a very tricky question here. I've been benging my head on this issue for several hours with no success.
I am building an application to be deployed on numerous machines, with different cultures.
As a precautionary I decided to use the Culture class to help convert between string to dates.
I noticed that when I change my windows operation system date from :
10/07/2011 to 10-07-2011
The CurrentCulture doesn't get updated, I keep seeing the dates as 10/07/2011.
Why is that? Is there any workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在 IIS 环境中(或在 Web.config 中更好)而不是在操作系统中更改文化。
这样您就可以保证所有机器都在相同的文化上工作。
尝试将以下行添加到您的 web.config:
只需将 he-IL 更改为您提供的文化
You need to change the Culture in the IIS environment (or better in Web.config) and not in the OS.
that way you'll Guarantee that all the machines will work on the same Culture.
try to add the following line to your web.config:
just change the he-IL to your proffered culture
它对我来说可以正常工作,但只有在我重新启动我的应用程序之后。我假设当前区域性是在应用程序启动时加载并缓存的,因此,为了使更改生效,您必须重新启动应用程序。
It works correctly for me, but only after I restart my application. I assume the current culture is loaded at the start of the application and cached, so, for the change to take effect, you have to restart the application.
只要该值仍然可以被解释为日期,它就会始终被格式化为您的 CurrentCulture。这是设计使然。
您需要显式更改 CurrentCulture,以便数据显示(或转换)为新格式。查看 CurrentCulture 来了解数据在您端的显示方式。
A long as the value can still be interpreted as a date, it will always be formatted to your CurrentCulture. This is by design.
You need to explicitly change CurrentCulture, so data shows (or is converted) to a new format. Look at CurrentCulture as how data is going to be displayed on your end.