且构网

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

更改系统日期时间格式c#

更新时间:2021-08-27 01:24:54

我尝试手动更改您的问题中提到的注册表项。

I tried manually changing the registry keys mentioned in your question.

这是我所做的:


  • 按下 Win + R 并键入 regedit以获取注册表编辑器。

  • 在树到计算机→ HKEY_CURRENT_USER→控制面板→国际。

  • 双击 sShortDate条目并将其值更改为 yyyy / MM / dd。

  • Pressed Win+R and type 'regedit' to get the Registry Editor.
  • Navigated the tree to Computer → HKEY_CURRENT_USER → Control Panel → International.
  • Double clicked the 'sShortDate' entry and changed the value to 'yyyy/MM/dd'.

然后我打开Windows资源管理器,所有日期都以新格式显示,因此在注册表中绝对是正确的位置。

I then opened Windows Explorer and all of the dates were shown in the new format, so this is definitely the right place in the registry.

然后我尝试使用您提供的代码来修改注册表,它也更改了资源管理器中显示的日期。

I then tried the code you supplied to modify the registry and it, too, is changing the date shown in Explorer.

因此,使我相信Windows任务栏时钟不会对此设置的更改做出反应。我通过从任务管理器中杀死并重新启动 explorer.exe来确认这一点。如果重新启动资源管理器,您也应该看到更改生效。

So, this leads me to believe that the Windows taskbar clock does not react to changes to this setting. I confirmed this by killing and restarting 'explorer.exe' from the Task Manager. If you restart Explorer you too should see the change take effect.

编辑:.NET中似乎没有任何功能。用于直接设置区域设置。但是,您可以使用P / Invoke通过C ++ Win API对其进行设置,然后应该使系统时钟(和其他应用程序)收到更改通知。请参见此讨论

there appears to be no facility in .NET for setting the locale settings directly. You can, however, use P/Invoke to set it via the C++ Win API which should then cause the system clock (and other applications) to be notified of the change. See this discussion.