Sign in Join

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

Mailing lists / lazarus / 2014-04

Now function - returning UTC?

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

David Taylor

I have a version of the Now function which works in Windows and returns UTC.

function NowUTC: TDateTime;
var
   system_datetime: TSystemTime;
begin
   GetSystemTime (system_datetime);
   Result := SystemTimeToDateTime (system_datetime);
end;

I've had an enquiry for a version of this for Lazarus, to run on the Raspberry Pi (Debian) but my Linux knowledge isn't up to writing an equivalent. I've searched and don't see GetSystemTime in FreePascal.

Can anyone help with this apparently simple problem?

Thanks,
David

Reply by email

silvioprog
to David Taylor

2014-04-19 12:37 GMT-03:00 David Taylor :

Show quoted text 10 lines
I have a version of the Now function which works in Windows and returns UTC. function NowUTC: TDateTime; var system_datetime: TSystemTime; begin GetSystemTime (system_datetime); Result := SystemTimeToDateTime (system_datetime); end;

I'm used this:

class function TDropboxOAuthUtil.GenerateTimeStamp: string;
{$IFNDEF FPC}
var
  VCurTime: TSystemTime;
{$ENDIF}
begin
{$IFNDEF FPC}
  GetSystemTime(VCurTime);
{$ENDIF}
  Result := IntToStr(DateTimeToUnix({$IFDEF
FPC}LocalTimeToUniversal(Now){$ELSE}
    SystemTimeToDateTime(VCurTime){$ENDIF}));
end;
Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140419/12ee471b/attachment.html>

Reply by email

Luca Olivetti
to Luca Olivetti

El 19/04/14 20:55, Luca Olivetti ha escrit:

Show quoted text 5 lines
El 19/04/14 17:37, David Taylor ha escrit: > Can anyone help with this apparently simple problem? lazutf8sysutils has a NowUTC function already defined

BTW, the name of the unit isn't really meaningful (NowUTC and GetTickCount64, the only 2 functions defined in that unit, don't seem to have any relation with utf8).

Bye

Luca Olivetti Wetron Automation Technology http://www.wetron.es Tel. +34 935883004 Fax +34 935883007

Reply by email

Felipe Monteiro de Carvalho
to Luca Olivetti: El 19/04/14 20:55, Luca Olivetti ha escrit: BTW, the name of the unit isn't really…
Luca Olivetti wrote
BTW, the name of the unit isn't really meaningful (NowUTC and GetTickCount64, the only 2 functions defined in that unit, don't seem to have any relation with utf8).

The idea was that one day it would contain utf8 versions of sysutils routines too + extra functions which are alternatives to rtl ones but not related to text encoding like the 2 you mention.

Felipe Monteiro de Carvalho

Reply by email

Michael Schnell
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 8 lines
On Sat, Apr 19, 2014 at 4:07 PM, Luca Olivetti wrote: > BTW, the name of the unit isn't really meaningful (NowUTC and > GetTickCount64, the only 2 functions defined in that unit, don't seem to > have any relation with utf8). The idea was that one day it would contain utf8 versions of sysutils routines too + extra functions which are alternatives to rtl ones but not related to text encoding like the 2 you mention.

IMHO, these functions would be better located in the FPC RTL, as they are more "general" than what the Lazarus library is about.

Same might be true for UTF8 helper functions.

-Michael

Reply by email

Felipe Monteiro de Carvalho
to Michael Schnell
Michael Schnell wrote
IMHO, these functions would be better located in the FPC RTL, as they are more "general" than what the Lazarus library is about. Same might be true for UTF8 helper functions.

Some years ago when the units were created I offered to add them to the RTL and they were rejected with the argumentation that the RTL does not support UTF-8 and doesn't plan to. So that's why they are located in LazUtils instead.

Felipe Monteiro de Carvalho

Reply by email