Click here to Skip to main content
11,929,166 members (57,840 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked

Change System Date Format At Runtime

, 16 Mar 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Change System Date Format At Runtime


You may sometimes need to change your system Date format at run time. C# has namespace ‘using Microsoft.Win32’ which helps you to change your system date and currency format.

Using the Code

First, you just have to use namespace using Microsoft.Win32

Then use RegistryKey class to access Current user preferences. Then you can set value for date format using RegistryKey’s object.

//    RegistryKey rkey = Registry.CurrentUser.OpenSubKey
//                (@"Control Panel\International", true);
//      rkey.SetValue("sShortDate", "d/M/yy");
//    rkey.SetValue("sLongDate","dd/MM/yy");
  • d:

    Use this to specify the numeric value for the day of the month.

    Eg. d (1) or dd(01) or ddd(MON) or dddd(MONDAY).

  • M:

    These display the months in numeric form.

    Eg. M(1) or MM(01) or MMM(JAN) or MMMM(JANUARY).

  • y:

    Use this to specify the numeric value for the year to different digits.

    Eg. y(9) or yy(09) or yyyy(2009).

Apart from these, you may also use follow:
  • t: The first character of the AM/PM designator.

    11/03/2011 1:45:30 PM

  • tt: The AM/PM designator.

    11/03/2011 1:45:30 PM

  • s: The second, from 0 through 59.

    11/03/2011 1:45:09 PM

  • ss: The second, from 00 through 59.

    11/03/2011 1:45:09 PM. and so on

Points of Interest

This is very easy code to change system date format at runtime. Following are the class methods with their uses.
// RegistryKey, represents a key-level node at windows registry
// Registry, represents a root keys in windows registry
// CurrentUser, reads windows registry base key HKEY_CURRENT_USER
You can use this code to change system currency format too.


15 March 2011: Initial release


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

QuestionHow to set time? Pin
Member 938534217-Sep-13 0:00
memberMember 938534217-Sep-13 0:00 
GeneralReason for my vote of 5 very nice tips... Its work Pin
Sona s25-Mar-11 4:22
memberSona s25-Mar-11 4:22 
GeneralYou r going good best wishes... Pin
Bhavna v24-Mar-11 19:12
memberBhavna v24-Mar-11 19:12 
GeneralReason for my vote of 5 Nice tips, I just have been lookung ... Pin
Bhavna v16-Mar-11 17:02
memberBhavna v16-Mar-11 17:02 
GeneralDon't do that! Pin
Bernhard Hiller16-Mar-11 23:03
memberBernhard Hiller16-Mar-11 23:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 16 Mar 2011
Article Copyright 2011 by Brijesh Kr
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid