Machine Culture and DateTime

丶灬走出姿态 提交于 2019-12-13 07:27:50

问题


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?


回答1:


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.




回答2:


if your windows service is running on a system account you need to apply the correct (en-GB) language settings also to reserved accounts



来源:https://stackoverflow.com/questions/7119159/machine-culture-and-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!