Sign in Join

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

Mailing lists / fpc-pascal / 2009-04

Re: getting system time in linux

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Rainer Stratmann
to Jan De Bleser: How is it possible to get the system time in linux? It used to be possible by using…

Am Freitag, 10. April 2009 16:47 schrieb Jan De Bleser:

You can try this. Not all uses are needed, you have to find out. Rainer

uses
crt,
{$ifdef linux}
baseunix,
unix,
termio, // serial
linux,
sysutils,
dateutils,
unixutil;
{$else}
windows;
{$endif}

procedure mylo_os_gettime( var hour , minute , second , sec1000 : word );
var
{$ifdef linux}  // LINUX
 datetime : tdatetime;
{$else}
 st : systemtime;
{$endif}
begin
 {$ifdef linux} // LINUX
 datetime := time;
 hour     := hourof( datetime );
 minute   := minuteof( datetime );
 second   := secondof( datetime );
 sec1000  := millisecondof( datetime );
 {$else}        // WINDOWS
 getlocaltime( st );
 hour    := st.whour;
 minute  := st.wminute;
 second  := st.wsecond;
 sec1000 := st.wmilliseconds;
 {$endif}
end;
procedure mylo_os_getdate( var year , month , day : word );
var
{$ifdef linux}
 datetime : tdatetime;
{$else}
 st : systemtime;
{$endif}
begin
 {$ifdef linux}
 datetime := date;
 year     := yearof( datetime );
 month    := monthof( datetime );
 day      := dayof( datetime );
 {$else}
 getlocaltime( st );
 year   := st.wyear;
 month  := st.wmonth;
 day    := st.wday;
 {$endif}
end;
Show quoted text 17 lines
Hi, How is it possible to get the system time in linux? It used to be possible by using 'getsystemtime' of the unit oldlinux, but this unit is no longer available on my compiler... The thing I want to use it for is: I get a packet form libpcap, with the time of receival in system time. I want to convert this time to system time by doing something like: rcvTime := packet.rcvTime + (now - getSystemTime) Kind regards, Jan _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Jan De Bleser

Hi,

How is it possible to get the system time in linux? It used to be possible by using 'getsystemtime' of the unit oldlinux, but this unit is no longer available on my compiler...

The thing I want to use it for is: I get a packet form libpcap, with the time of receival in system time.
I want to convert this time to system time by doing something like: rcvTime := packet.rcvTime + (now - getSystemTime)

Kind regards,

Jan

Reply by email

Marco van de Voort
to Jan De Bleser

In our previous episode, Jan De Bleser said:

Show quoted text 9 lines
How is it possible to get the system time in linux? It used to be possible by using 'getsystemtime' of the unit oldlinux, but this unit is no longer available on my compiler... The thing I want to use it for is: I get a packet form libpcap, with the time of receival in system time. I want to convert this time to system time by doing something like: rcvTime := packet.rcvTime + (now - getSystemTime)

fptime probably. Note that not all *nix systems have system time set to GMT.

Reply by email

Jan De Bleser
to Marco van de Voort
Marco van de Voort wrote 17 lines
In our previous episode, Jan De Bleser said: > How is it possible to get the system time in linux? > It used to be possible by using 'getsystemtime' of the unit oldlinux, > but this unit is no longer available on my compiler... > > The thing I want to use it for is: I get a packet form libpcap, with the > time of receival in system time. > I want to convert this time to system time by doing something like: > rcvTime := packet.rcvTime + (now - getSystemTime) > fptime probably. Note that not all *nix systems have system time set to GMT. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Yeah thanks, That did the trick.
I was a bit confused because hwclock doesn't give you the real hardware clock :s

Reply by email

Jan De Bleser
to Rainer Stratmann: You can try this. Not all uses are needed, you have to find out. Rainer uses {$ifdef…

Thanks Rainer,
In the end I solved it using UnixToDateTime(FpTime), which is easier of course...

Rainer Stratmann wrote 88 lines
Am Freitag, 10. April 2009 16:47 schrieb Jan De Bleser: You can try this. Not all uses are needed, you have to find out. Rainer uses crt, {$ifdef linux} baseunix, unix, termio, // serial linux, sysutils, dateutils, unixutil; {$else} windows; {$endif} procedure mylo_os_gettime( var hour , minute , second , sec1000 : word ); var {$ifdef linux} // LINUX datetime : tdatetime; {$else} st : systemtime; {$endif} begin {$ifdef linux} // LINUX datetime := time; hour := hourof( datetime ); minute := minuteof( datetime ); second := secondof( datetime ); sec1000 := millisecondof( datetime ); {$else} // WINDOWS getlocaltime( st ); hour := st.whour; minute := st.wminute; second := st.wsecond; sec1000 := st.wmilliseconds; {$endif} end; procedure mylo_os_getdate( var year , month , day : word ); var {$ifdef linux} datetime : tdatetime; {$else} st : systemtime; {$endif} begin {$ifdef linux} datetime := date; year := yearof( datetime ); month := monthof( datetime ); day := dayof( datetime ); {$else} getlocaltime( st ); year := st.wyear; month := st.wmonth; day := st.wday; {$endif} end; > Hi, > > How is it possible to get the system time in linux? > It used to be possible by using 'getsystemtime' of the unit oldlinux, > but this unit is no longer available on my compiler... > > The thing I want to use it for is: I get a packet form libpcap, with the > time of receival in system time. > I want to convert this time to system time by doing something like: > rcvTime := packet.rcvTime + (now - getSystemTime) > > Kind regards, > > Jan > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email