本文介绍了如何在Inno Setup中使用UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Inno Setup脚本中,我有一个从当前时间创建的字符串,该字符串存储在注册表中.我喜欢这样:

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;

问题是我需要使用UTC时间制作字符串.有谁能告诉我我该怎么做?

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?

谢谢.

推荐答案

您已经知道(基于您的替代尝试),则可以使用 GetSystemTime WinAPI函数:

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 '[email protected]';

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声明来自ISXKB(未终止).


GetSystemTime declaration is from ISXKB (not defunct).

这篇关于如何在Inno Setup中使用UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:33