且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在运行时更改系统日期格式

更新时间:2023-09-18 23:32:34

首先关闭:甚至不要尝试。



如果您开始使用系统日期格式,您将影响了计算机上许多其他程序,并惹恼了很多用户。如果一个应用程序试图在我的电脑上执行此操作,它将被解除极端偏见,我会找回我的钱。



如果您的应用需要一个特定的日期格式,然后在您显示数据时提供格式信息,并在您从用户那里读取日期信息时使用适当的格式(但即便如此,如果不是他使用的话,您可能会感到困惑和烦恼在他的计算机上 - ***在用户习惯的任何地方输入。)



格式化不同的文化并不困难,并指定绝对格式输出中的日期非常简单:为显示格式化日期时间 - 格式字符串描述 [ ^ ]显示您需要的位数。



Bu改变整体系统设置?糟糕的想法 - 这就是为什么要做到这一点并不容易!
First off: don't even try.

If you start playing with the system date format you will affect a heck of a lot of other programs on the computer and annoy a lot of users. If an application tried to do that to my PC, it would be uninstalled with extreme prejudice, and I'd be looking for my money back.

If your app needs a specific date format, then provide it the formatting information when you display data, and use the appropriate format when you read date info from the user (but even then, you will likely confuse and annoy him if it isn't what he is used to on his computer - it's best to take input in whatever the user is used to).

Formatting for different cultures isn't difficult, and specifying an absolute format for dates in output is really easy: Formatting a DateTime for display - format string description[^] shows the bits you need.

But changing overall system settings? Bad idea - and that's why it's not easy to do any more!