更改系统的日期格式(通过C#) [英] Change date format of system (by C#)

查看:89
本文介绍了更改系统的日期格式(通过C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好
如何通过c#将系统的日期格式更改为yyyy / MM / dd?

(在控制面板的区域和语言中)

非常感谢

Hi How can I change the date format of system to yyyy/MM/dd by c#?
(in "Regional and Language" of conrol panel)
Thanks very much

推荐答案

首先,您应该想:为什么这样做?



嗯,我可以想象你可以创建另一个系统调整实用程序,它可以以一种比操作系统中已有的方式更方便的方式修改许多设置。这不是一个非常有效的活动,但我可以想象一些用户在收到适当的警告后会认为这样的实用程序合法。



在几乎所有其他情况下,当你在一些应用程序的水平上解决一些应用的问题,这样做将是一个真正的犯罪对用户,破坏。微软不鼓励这样做,据我所知,没有API可以做这样的事情(以及许多其他系统设置)。



如果你仍然认为您有理由修改这些系统设置,您可以通过修改某些系统注册表记录来实现。对于当前用户,关键是:

First of all, you should think: why doing so?

Well, I can imagine that you could create yet another "System tweaks" utility which can modify many settings in a way a bit more convenient that the one already available in the OS. This is not a very productive activity, but I can imagine some users, after receiving proper warnings, will consider such utility legitimate.

In nearly all other cases, when you do it at the level of some application solving some applied problems, doing so would be a real crime against the user, the sabotage. Doing so is discouraged by Microsoft and, as far as I know, there is no API to do such thing (as well as many other system settings).

If you still think you have a reason to modify these system setting, you can do it by modifying some system registry records. For a current user, the key is:
HKEY_CURRENT_USER\Control Panel\International



向下钻取从这一点开始,如果你想。



参见: http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey%28v=vs.110%29.aspx [ ^ ]。



你应该明白它有多危险。例如,如果您提供无效的时间格式,则可能会破坏许多应用程序和系统实用程序的功能。考虑一下我警告过你。



现在,也许你想重新思考一下这个想法,只为一个应用程序更改设置。您可以只更改某些线程的当前文化和UI文化,尤其是UI线程。请参阅:

http://msdn.microsoft .com / zh-cn / library / system.threading.thread.currentculture.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.globalization .cultureinfo.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system。 globalization.cultureinfo.clearcacheddata.aspx [ ^ ]。



-SA


Drill down from this point, if you want.

See also: http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey%28v=vs.110%29.aspx[^].

You should understand how dangerous it can be. If you, say, provide an invalid time format, it can screw up the functionality of many applications and system utilities. Consider I warned you.

Now, maybe you want to rethink the idea and change the settings only for one application. You can just change the current culture and UI culture of some of your threads, in particular, the UI thread. Please see:
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx[^],
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture.aspx[^],
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx[^],
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.clearcacheddata.aspx[^].

—SA


这篇关于更改系统的日期格式(通过C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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