Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-05

DateTimeToFileDate

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Carsten Bager

If I do this on a Linux machine

(Free Pascal Compiler version 2.4.2 [2010/11/08] for i386)

  WriteLn(DateTimeToFileDate(Now));
  WriteLn(trunc((now-EncodeDate(1970,1,1))*86400));

I get this
1305786833
1305794033

There is a difference of 7200= 2 hours.

Is this correct?

I would not expect a difference of 2 hours (the deference from UTC).

Regards
Carsten

Ludo Brands
to Carsten Bager

Delphi FileDate is UTC time based because the windows API FILETIME structure is UTC based. Delphi exposes the FileTimeToLocalFileTime API call to get the local time.
The fpc unix implementation uses LocalToEpoch (unixutil.pp) which has the folloxing comments:
{
Transforms local time (year,month,day,hour,minutes,second) to Epoch time (seconds since 00:00, january 1 1970, corrected for local time zone) }

I guess fpc wants to be Delphi compatible as much as possible.

Ludo

Earlier message 28 lines
-----Message d'origine----- De : De la part de Carsten Bager Envoyé : jeudi 19 mai 2011 08:58 À : FPC-Pascal users discussions Objet : [fpc-pascal] DateTimeToFileDate If I do this on a Linux machine (Free Pascal Compiler version 2.4.2 [2010/11/08] for i386) WriteLn(DateTimeToFileDate(Now)); WriteLn(trunc((now-EncodeDate(1970,1,1))*86400)); I get this 1305786833 1305794033 There is a difference of 7200= 2 hours. Is this correct? I would not expect a difference of 2 hours (the deference from UTC). Regards Carsten
Ludo Brands
to Ludo Brands

The other reason for doing so is that unix stores internally all dates as UTC, including the dates used in the file system.

Ludo

Earlier message 47 lines
-----Message d'origine----- De : De la part de Ludo Brands Envoyé : jeudi 19 mai 2011 09:36 À : ; 'FPC-Pascal users discussions' Objet : RE : [fpc-pascal] DateTimeToFileDate Delphi FileDate is UTC time based because the windows API FILETIME structure is UTC based. Delphi exposes the FileTimeToLocalFileTime API call to get the local time. The fpc unix implementation uses LocalToEpoch (unixutil.pp) which has the folloxing comments: { Transforms local time (year,month,day,hour,minutes,second) to Epoch time (seconds since 00:00, january 1 1970, corrected for local time zone) } I guess fpc wants to be Delphi compatible as much as possible. Ludo -----Message d'origine----- De : De la part de Carsten Bager Envoyé : jeudi 19 mai 2011 08:58 À : FPC-Pascal users discussions Objet : [fpc-pascal] DateTimeToFileDate If I do this on a Linux machine (Free Pascal Compiler version 2.4.2 [2010/11/08] for i386) WriteLn(DateTimeToFileDate(Now)); WriteLn(trunc((now-EncodeDate(1970,1,1))*86400)); I get this 1305786833 1305794033 There is a difference of 7200= 2 hours. Is this correct? I would not expect a difference of 2 hours (the deference from UTC). Regards Carsten