4

I have the following timestamp: 1444288186967.

When I put that in a Epoch Converter, I get correctly 08 Oct 2015 07:09:46 as result.

However, when I use (as mentioned in another post) the function UnixToDateTime(const AValue: Int64): TDateTime I get 02 Sep 47737 11:02:47. Strange, isn't it?

My code (using TMS Aurelius)

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

Where FHit.TimestampUntil is an Int64 as the UnixToDateTime function expects.

The Person.EndDate.Value is a TMS Aurelius nullable TDateTime.

How is it possible that I get such date as result?

Community
  • 1
  • 1
davepaul12
  • 391
  • 4
  • 15

1 Answers1

7

Normally Unix timestamps are in seconds since 1.1.1970. However, the value 1444288186967 is in milliseconds. Divide by 1000 and round and you will get the expected date and time 8.10.2015 7:09:47

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

Edit2 shows 8.10.2015 7:09:47

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • The [`UnixToDateTime()` documentation](http://docwiki.embarcadero.com/Libraries/en/System.DateUtils.UnixToDateTime) says: "*Unix date-and-time values are encoded as the number of **seconds** since midnight at the start of January 1, 1970*", and the [Epoch Convertor](http://www.epochconverter.com/#tools) says "*Assuming that this timestamp is in **milliseconds**.*" for `1444288186967`. – Remy Lebeau Oct 08 '15 at 23:57