C# change system date time format -


i looking way change system's date time format 12 hour 24 hour. suppose, currently, have system time in 12 or 24 hour format , want change 24 hour format programatically. how possible ?

thanks

you can use setlocaleinfo api function locale_itime constant passed lctype parameter.

edit:

here example of setting 12-hour time format.

using system; using system.runtime.interopservices;  namespace dllimporttest {     internal static class program     {         private const string timeformat12hour = "0";         private const string timeformat24hour = "1";          public static void main(string[] args)         {             var ok = windowsapi.setlocaleinfo(0, windowsapi.locale_itime, timeformat12hour);             if (!ok)                 throw new applicationexception(string.format("windows api call error {0}.", marshal.getlastwin32error()));         }     }      internal static class windowsapi     {         public const int locale_itime = 0x00000023;          [dllimport("kernel32.dll", setlasterror = true, charset = charset.unicode)]         public static extern bool setlocaleinfo(uint locale, uint lctype, string lcdata);     } } 

please note, setlocalinfo documentation states necessary broadcast wm_settingchange message top-level windows after making international change system parameters. doing require using of windows api function sendmessagetimeout. part omitted in example.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -