I need to change/update/set my system (windows7) default dateTime format programatically and permanently until I change it myself through code or through windows GUI
I have tried a lot of solutions like this one from 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 + "");
The closest and well reputed answer is following from from Set Default DateTime Format c#, I tried this solution but it did not help me. As It does not change my system datetime format (shown in taskbar). And after I restart the app having this code, I again get the old format before this code is executed.
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 + "");
}
}
}