[fpc-pascal] DateTimeToUnix bug?
John Coppens
john at jcoppens.com
Tue Dec 30 20:29:11 CET 2008
On Tue, 30 Dec 2008 09:25:29 -0700
"Seth Grover" <sethdgrover at gmail.com> wrote:
> It seems to me that 09-16-1989 12:00:01 should be 621950401, not
> 621950400.
This seems to be rounding error - if you put 1 ms (milisecond) in the
seconds test, the result comes out right. For consecutive seconds, and
ms = 0:
09-16-1989 12:00:00 = 621950400 = 09-16-1989 12:00:00
09-16-1989 12:00:01 = 621950400 = 09-16-1989 12:00:00
09-16-1989 12:00:02 = 621950402 = 09-16-1989 12:00:02
09-16-1989 12:00:03 = 621950403 = 09-16-1989 12:00:03
09-16-1989 12:00:04 = 621950403 = 09-16-1989 12:00:03
09-16-1989 12:00:05 = 621950404 = 09-16-1989 12:00:04
09-16-1989 12:00:06 = 621950406 = 09-16-1989 12:00:06
09-16-1989 12:00:07 = 621950407 = 09-16-1989 12:00:07
09-16-1989 12:00:08 = 621950407 = 09-16-1989 12:00:07
09-16-1989 12:00:09 = 621950408 = 09-16-1989 12:00:08
09-16-1989 12:00:10 = 621950410 = 09-16-1989 12:00:10
09-16-1989 12:00:11 = 621950411 = 09-16-1989 12:00:11
09-16-1989 12:00:12 = 621950411 = 09-16-1989 12:00:11
09-16-1989 12:00:13 = 621950412 = 09-16-1989 12:00:12
with ms = 1:
09-16-1989 12:00:00 = 621950400 = 09-16-1989 12:00:00
09-16-1989 12:00:01 = 621950401 = 09-16-1989 12:00:01
09-16-1989 12:00:02 = 621950402 = 09-16-1989 12:00:02
09-16-1989 12:00:03 = 621950403 = 09-16-1989 12:00:03
09-16-1989 12:00:04 = 621950404 = 09-16-1989 12:00:04
09-16-1989 12:00:05 = 621950405 = 09-16-1989 12:00:05
09-16-1989 12:00:06 = 621950406 = 09-16-1989 12:00:06
09-16-1989 12:00:07 = 621950407 = 09-16-1989 12:00:07
09-16-1989 12:00:08 = 621950408 = 09-16-1989 12:00:08
09-16-1989 12:00:09 = 621950409 = 09-16-1989 12:00:09
09-16-1989 12:00:10 = 621950410 = 09-16-1989 12:00:10
09-16-1989 12:00:11 = 621950411 = 09-16-1989 12:00:11
09-16-1989 12:00:12 = 621950412 = 09-16-1989 12:00:12
John
I slightly modified the test program:
program Project1;
uses
Classes,
SysUtils,
DateUtils;
var
utime : longword;
sec : word;
currentDt : TDateTime;
convertedDt : TDateTime;
begin
for sec := 0 to 59 do begin
currentDt := EncodeDateTime(1989, 9, 16, 12, 0, sec, 1);
utime := DateTimeToUnix(currentDt);
convertedDt := UnixToDateTime(utime);
writeln(FormatDateTime('mm/dd/yyyy HH:nn:ss', currentDt) + ' = ' +
IntToStr(utime) + ' = ' +
FormatDateTime('mm/dd/yyyy HH:nn:ss',
convertedDt));
end;
end.
More information about the fpc-pascal
mailing list