Forum Discussion

jackson_1's avatar
jackson_1
Frequent Contributor
13 years ago
Solved

how to set the system short date format

hi all,



 i want to reset the current system short date format, how can i change it through the script?

for example:

current: dd/mm/yyyy set into yyyy/mm/dd.



  • Hi Jackson,



    You can use the aqEnvironment.SetLocaleInfo method for this purpose:



    function Test()

    {

      var WM_SETTINGCHANGE = 0x001A;



      if (aqEnvironment.SetLocaleInfo(Win32API.LOCALE_SYSTEM_DEFAULT, Win32API.LOCALE_SSHORTDATE, "yyyy/MM/dd"))

      {

        // If no error, notify all running applications about the settings change

        Win32API.SendMessage(Win32API.HWND_TOPMOST, Win32API.WM_SETTINGCHANGE, 0, 0);

        Log.Message("The date format was changed successfully.");

      }

    }

3 Replies

  • jackson_1's avatar
    jackson_1
    Frequent Contributor





    Hi Kosova,


    Thanks very much,




    share the Delphi Script:

    Funcation ResetSystemShortDtaeFormat(format: string);


    var 

        WM_SETTINGCHANGE;   

    begin   


    WM_SETTINGCHANGE: = '0x001A';


    if (aqEnvironment.SetLocaleInfo(Win32API.LOCALE_SYSTEM_DEFAULT,Win32API.LOCALE_SSHORTDATE,format)) then


    begin

            Win32API.SendMessage(Win32API.HWND_TOPMOST,WM_SETTINGCHANGE,0,0);

            Log.Message('The Date Format was changed successfully');


    end;

    end;










  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Jackson,



    You can use the aqEnvironment.SetLocaleInfo method for this purpose:



    function Test()

    {

      var WM_SETTINGCHANGE = 0x001A;



      if (aqEnvironment.SetLocaleInfo(Win32API.LOCALE_SYSTEM_DEFAULT, Win32API.LOCALE_SSHORTDATE, "yyyy/MM/dd"))

      {

        // If no error, notify all running applications about the settings change

        Win32API.SendMessage(Win32API.HWND_TOPMOST, Win32API.WM_SETTINGCHANGE, 0, 0);

        Log.Message("The date format was changed successfully.");

      }

    }
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    I'm glad I could help!



    A few notes about your DelphiScript version:

    * If you're not going to return a value from the subroutine, it's better to declare it as a procedure.

    * I'd also recommend declaring WM_SETTINGCHANGE as const instead of var.

    * The DelphiScript hexadecimal prefix is $.

    procedure ResetSystemShortDateFormat(format: string);

    const WM_SETTINGCHANGE = $001A;

    begin

      if aqEnvironment.SetLocaleInfo(Win32API.LOCALE_SYSTEM_DEFAULT, Win32API.LOCALE_SSHORTDATE, format) then

      begin

        Win32API.SendMessage(Win32API.HWND_TOPMOST, WM_SETTINGCHANGE, 0, 0);

        Log.Message('Date format was changed successfully.');

      end;

    end;