【问题标题】:Why do I get a result many thousands of years in the future when I call UnixToDateTime?当我调用 UnixToDateTime 时,为什么会在数千年后得到结果?
【发布时间】:2016-01-05 16:19:27
【问题描述】:

我有以下时间戳:1444288186967

当我把它放在 Epoch Converter 中时,我得到了正确的结果 08 Oct 2015 07:09:46

但是,当我使用(如 another post 中所述)function UnixToDateTime(const AValue: Int64): TDateTime 时,我得到 02 Sep 47737 11:02:47。很奇怪,不是吗?

我的代码(使用 TMS Aurelius)

Person.EndDate.Value := UnixToDateTime(FHit.TimestampUntil);

其中FHit.TimestampUntilInt64,正如UnixToDateTime 函数所期望的那样。

Person.EndDate.Value 是 TMS Aurelius 可为空的 TDateTime

我怎么可能得到这样的日期?

【问题讨论】:

    标签: delphi unix datetime time timestamp


    【解决方案1】:

    自 1.1.1970 以来,通常 Unix 时间戳以秒为单位。但是,1444288186967 的值以毫秒为单位。除以 1000 并取整,您将得到预期的日期和时间 8.10.2015 7:09:47

      i64 := round(1444288186967/1000);
      dt := UnixToDateTime(i64);
      Edit2.Text := DateTimeToStr(dt);
    

    Edit2 显示 8.10.2015 7:09:47

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 2012-10-27
    • 2012-10-18
    • 1970-01-01
    • 2015-04-06
    相关资源
    最近更新 更多