I have this time from an server: 1475245457452 The Date and Time for this is: 30.9.2016, 16:24:17
How can I convert this 1475245457452 in Delphi to a correct Date and Time?
I have this time from an server: 1475245457452 The Date and Time for this is: 30.9.2016, 16:24:17
How can I convert this 1475245457452 in Delphi to a correct Date and Time?
You did not say, but I can guess that this quantity is actually milliseconds, measured from the Unix epoch. So convert them using UnixToDateTime
from the System.DateUtils
unit:
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.DateUtils;
begin
Writeln(DateTimeToStr(UnixToDateTime(1475245457452 div 1000)));
end.
I have divided by 1000
to convert into seconds because UnixToDateTime
expects the time in seconds rather than milliseconds.
If you wish to retain the millisecond part of the time then you can readily increment the date time value by the remainder of the division.
It is important to stress that time is always measured in some unit system, and relative to some origin, or epoch. It's never enough to know just a value, but you have to know both the units and the epoch. Yes, it is often easy enough to guess these, but it would usually be better to read the specification of the software producing the time value to find out definitively what the value is.