linux - 在 FreePascal 中从 Windows 到 Linux 的时区代码转换

标签 linux windows freepascal

我有这段代码可以在 Windows 下的 FreePascal 中运行,需要将其转换为 Linux,但我完全不知道时区偏差值:

function DateTimeToInternetTime(const aDateTime: TDateTime): String;
{$IFDEF WIN32}
var
  LocalTimeZone: TTimeZoneInformation;
{$ENDIF ~WIN32}
begin
{$IFDEF WIN32}
  // eg. Sun, 06 Nov 1994 08:49:37 GMT  RFC 822, updated by 1123
  Result := FormatDateTime('ddd, dd mmm yyyy hh:nn:ss', aDateTime);
  // Get the Local Time Zone Bias and report as GMT +/-Bias
  GetTimeZoneInformation(LocalTimeZone);
  Result := Result + 'GMT ' + IntToStr(LocalTimeZone.Bias div 60);
{$ELSE}
  // !!!! Here I need the above code translated !!!!
  Result := 'Sat, 06 Jun 2009 18:00:00 GMT 0000';
{$ENDIF ~WIN32}
end;

最佳答案

这个人有答案:http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg08467.html

因此您需要添加 uses 子句:

uses unix,sysutils,baseunix

保存时间/时区的变量:

 var
   timeval: TTimeVal;
   timezone: PTimeZone;

..并获得“向西分钟”。

{$ELSE}
  Result := FormatDateTime('ddd, dd mmm yyyy hh:nn:ss', aDateTime);
  TimeZone := nil;
  fpGetTimeOfDay (@TimeVal, TimeZone);
  Result := Result + 'GMT ' + IntToStr(timezone^.tz_minuteswest div 60);
{$ENDIF ~WIN32}

关于linux - 在 FreePascal 中从 Windows 到 Linux 的时区代码转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/961953/

相关文章:

windows - Windows 7 上的 StartServiceCtrlDispatcher 访问被拒绝

windows - Ant构建执行cordova

delphi - 对象在主程序中崩溃,但在移动到单元时不会崩溃

linux -/proc/kallsyms中的t和t有什么区别

c - 使用 main 中给出的参数在 C 中进行字符串解析

javascript - Node.js spawn/exec/execFile/win-spawn/cross-spawn 全部抛出错误 : spawn ENOENT

openssl - 调用 OpenSSL EVP 函数的 Delphi/Pascal 示例

linux是否可以清空一个目录下所有文件的内容

c - fork() 情况下的全局变量值

Pascal:Const 数组