Change System DateTime Formate Using API

//Declare System Date Time Settings Change

private const int WM_SETTINGCHANGE = 0x001A;
        private const int LOCALE_SSHORTDATE = 31; //'short date format string
        private const int LOCALE_SLONGDATE = 32; // 'long date format string

        [System.Runtime.InteropServices.DllImport("kernel32.dll", ExactSpelling = true, EntryPoint = "GetUserDefaultLCID")]
        private static extern int GetUserDefaultLCID();
        [System.Runtime.InteropServices.DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern long SetLocaleInfoA(int newLCDID, int constDate, string newFormat);

 


private void setDateTimeSettings()
         {
             string sNewFormat1 = "dd-MM-yyyy";
             string sCultureFormat = "";
             string strDateFormat=new string('1',25);
             long lngReturn = GetProfileStringA("Intl", "sShortDate", "", strDateFormat, strDateFormat.Length);
             string[] strDateTimeArray = DateTimeFormatInfo.CurrentInfo.GetAllDateTimePatterns();
             sCultureFormat=strDateTimeArray[0].ToString();
             if (Convert.ToString(sNewFormat1) != Convert.ToString(sCultureFormat))
             {
                 int intP = GetUserDefaultLCID();
                 SetLocaleInfoA(intP, LOCALE_SSHORTDATE, sNewFormat1);
                 SetLocaleInfoA(intP, LOCALE_SLONGDATE, sNewFormat1);
             }
         }

Ebook Download
View all
Learn
View all