首页 > 其他分享 >delphi 获取Unix 时间戳

delphi 获取Unix 时间戳

时间:2023-01-12 15:14:10浏览次数:35  
标签:UTC DateUtils delphi System 获取 Unix 时间 TDateTime

获取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时间转换为当地时间。

标签:UTC,DateUtils,delphi,System,获取,Unix,时间,TDateTime
From: https://www.cnblogs.com/txgh/p/17046700.html

相关文章