Wednesday, February 13, 2013

How to change date format of system using C# code?



This is the current date format of the System





This following C# code is used to change date format
The namespace of   RegistryKey is using Microsoft.Win32;



private void button1_Click(object sender, EventArgs e)
{
string DateFormat = txtDateFormat.Text.Trim();

string TimeFormat = txtTimeFormat.Text.Trim();

RegistryKey rkey = Registry.CurrentUser.OpenSubKey(@"ControlPanel\International", true);


///Set Values

rkey.SetValue("sTimeFormat", TimeFormat);

rkey.SetValue("sShortDate", DateFormat);


//Close the Registry

rkey.Close();
}





The new date format is displayed below



1 comment:

  1. Nice Article Fahad..
    Small mistake in this line..
    RegistryKey rkey = Registry.CurrentUser.OpenSubKey(@"ControlPanel\International", true);

    Replace ControlPanel instead of Control Panel
    after change it will work fine...

    ReplyDelete

Comment Here..