Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get a result many thousands of years in the future when I call UnixToDateTime?

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?

like image 402
davepaul12 Avatar asked Mar 14 '23 13:03

davepaul12


1 Answers

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

like image 126
Tom Brunberg Avatar answered Mar 17 '23 01:03

Tom Brunberg