delphi 获取Unix 时间戳

获取Unix 时间戳

代码

uses System.DateUtils;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //获取当前时间的 Unix 时间戳
  Memo1.Lines.Add(IntToStr(DateTimeToUnix(Now)));

  //根据Unix 时间戳 获取日期
  Memo1.Lines.Add(DateTimeToStr(UnixToDateTime(1000)));
end;

方法

System.DateUtils.DateTimeToUnix

function DateTimeToUnix(const AValue: TDateTime; AInputIsUTC: Boolean): Int64;

unit

System.DateUtils

TDateTime 值转换为 Unix/Linux 样式的日期和时间值。

Unix/Linux 日期和时间值是从自 1970 年 1 月 1 日零点开始所经过的秒数。

AInputIsUTC 是否是UTC时间,默认为TrueFalse时,将AValue转换成UTC时间,再返回。

System.DateUtils.UnixToDateTime

function UnixToDateTime(const AValue: Int64; AReturnUTC: Boolean): TDateTime;

unit

System.DateUtils

将 Unix/Linux 样式的日期和时间值转换为 TDateTime 值。

Unix/Linux 日期和时间值是从自 1970 年 1 月 1 日零点开始所经过的秒数。

AInputIsUTC 是否是UTC时间,默认为TrueFalse时,将返回值的UTC时间转换为当地时间。

posted @ 2023-01-12 14:59  txgh  阅读(409)  评论(0编辑  收藏  举报