我需要以编程方式永久更改/更新/设置我的系统(windows7)默认日期时间格式,直到我自己通过代码或通过 Windows GUI 更改它
我已经尝试了很多像这样来自Code Project的解决方案
Console.Write(DateTime.Now + "");
RegistryKey rkey = Registry.CurrentUser.OpenSubKey(@"
Control Panel\International", true);
rkey.SetValue("sShortDate", "dd/MM/yyyy");
rkey.SetValue("sLongDate", "dd/MM/yyyy");
Console.Write(DateTime.Now + "");
最接近且享有盛誉的答案来自Set Default DateTime Format c#,我尝试了此解决方案,但对我没有帮助。因为它不会改变我的系统日期时间格式(显示在任务栏中)。在我重新启动具有此代码的应用程序后,我在执行此代码之前再次获得旧格式。
using System;
using System.Globalization;
using System.Threading;
namespace test
{
public static class Program
{
public static void Main() {
Console.Write(DateTime.Now + "");// MessageBox.Show(DateTime.Now + "");
CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy";
culture.DateTimeFormat.LongTimePattern = "";
Thread.CurrentThread.CurrentCulture = culture;
Console.Write(DateTime.Now + "");// MessageBox.Show(DateTime.Now + "");
}
}
}