How to employ UTC in Inno Setup

对着背影说爱祢 提交于 2019-12-08 05:55:24

问题


In an Inno Setup script I have a string created from the current time that I store in the registry. I do like this:

function GetInstallDateTime (s : String ) : String;
Var 
   year, month, day, nr1, nr2 : String;
   sum : Byte;
   error: Integer;

begin   
   year := GetDateTimeString ('yy', #0, #0);
   nr1 := Copy(year, 1, 1);  
   nr2 := Copy(year, 2, 1);
   year := nr1+nr2;

   month := GetDateTimeString ('mm', #0, #0);
   nr1 := Copy(month, 1, 1);  
   nr2 := Copy(month, 2, 1);
   month := nr1 + nr2;

   day := GetDateTimeString ('dd', #0, #0);
   nr1 := Copy(day, 1, 1);  
   nr2 := Copy(day, 2, 1);
   day := nr1 + nr2;

   hour := GetDateTimeString ('hh', #0, #0);
   nr1 := Copy(hour, 1, 1);  
   nr2 := Copy(hour, 2, 1);
   hour := nr1 + nr2;
   Result := year + month + day + hour);
end;
[Registry]
Root: HKLM; Subkey: "Software\Testprogram\Settings"; ValueType: string; \
  ValueName: "mrg"; ValueData: {code:GetInstallDateTime|''}; \
  Flags: deletekey;

The problem is that I need to have the string made from UTC time. Is there anyone who could tell me how I could do that?

Thanks in advance.


回答1:


As you already know (based on your alternative attempt), you can use GetSystemTime WinAPI function:

type
  TSystemTime = record
    wYear: Word;
    wMonth: Word;
    wDayOfWeek: Word;
    wDay: Word;
    wHour: Word;
    wMinute: Word;
    wSecond: Word;
    wMilliseconds: Word;
  end;

procedure GetSystemTime(var lpSystemTime: TSystemTime);
  external 'GetSystemTime@kernel32.dll';

function GetInstallDateTime(Param: string): string;
var
  SystemTime: TSystemTime;
begin
  GetSystemTime(SystemTime);
  Result :=
    Format('%.2d%.2d%.2d%.2d', [
      SystemTime.wYear mod 100, SystemTime.wMonth, SystemTime.wDay, SystemTime.wHour]);
end;

GetSystemTime declaration is from ISXKB (not defunct).



来源:https://stackoverflow.com/questions/51525753/how-to-employ-utc-in-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!