在运行时更改系统日期格式 [英] Change system date format at runtime

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

问题描述

我正在使用asp.net c#,我想在运行时更改系统日期格式

所以我找到这段代码:

i am using asp.net c# , i want to change the system date format during runtime
so i find this code :

RegistryKey lkey = Registry.CurrentUser.OpenSubKey(@"Control Panel\International", true);

     
      lkey.SetValue("sShortDate", "dd/MM/yyyy");

     
      lkey.SetValue("sLongDate", "dd/MM/yyyy");





现在我遇到这个问题:



Now i face this problem :

System.Security.SecurityException: Requested registry access is not allowed.





i试图用信任级别解决它,但问题仍然存在。请问任何想法?



i tried to solve it using trust level, but the problem still.please any idea?

推荐答案

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



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



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



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



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!


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

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