机器文化和日期时间 [英] Machine Culture and DateTime

查看:128
本文介绍了机器文化和日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们以错误的方式设立了一个具有美国文化的服务器。后来我将区域设置,区域设置和IIS全球化更改为en-GB。



但是,我遇到了一个我写的Windows服务的问题。当DateTime.ToString()完成时,它仍然使用美国格式。我知道我可以指定我想要的字符串的文化,但我不想改变我的所有代码。它应该只是使用英国格式,因为它在机器设置中的任何地方变化。



也许有一个我错过的设置?除了更改代码之外,有人有任何建议吗?

解决方案

使用控制面板更改区域设置时,需要检查复选框将所有设置应用于当前用户帐户和默认用户配置文件。在XP中,这是在区域和语言选项的高级选项卡。



您的Windows服务可能运行在一个没有配置文件的帐户(例如LocalSystem)下,因此将使用默认用户配置文件设置。



您还可以使用RegEdit检查默认用户配置文件的区域设置 - 它们位于注册表项下的 HKEY_USERS\ .DEFAULT\Control Panel\International



然而,我会考虑更改代码 - Windows服务通常与机器的文化,您将避免维护头痛。


We set up a server wit the en-US culture by mistake. Later I changed the regional settings, the locale, and the IIS globalisation to en-GB.

However, I'm having a problem with a Windows service I've written. It's still using the US format whenever DateTime.ToString() is done. I know I can specify the culture I want the string to be in, but I don't want to change all my code. It should just use the UK format because it's changed everywhere in the machine settings.

Maybe there's a setting I've missed? Does anyone have any suggestions apart from changing the code?

解决方案

When you change the regional settings using Control Panel, you need to check the checkbox "Apply all settings to the current user account and to the default user profile". In XP this is on the Advanced tab of Regional and Language Options.

Your Windows Service is presumably running under an account without a profile (e.g. LocalSystem) so will use the default user profile settings.

You can also inspect the regional settings for the default user profile using RegEdit - they're under the registry key HKEY_USERS\.DEFAULT\Control Panel\International.

Nevertheless I would consider changing the code - a Windows Service should generally be agnostic about the machine's culture, and you'll be avoiding maintenance headaches down the line.

这篇关于机器文化和日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆