- Posts: 61
- Thank you received: 0
Question GetLocalTimeOffset return 0
- Vital
-
Topic Author
- Offline
- Junior Member
-
OS: Ubuntu 21.04 (64-bit)
CT: 7.3
Please Log in or Create an account to join the conversation.
- Sternas Stefanos
-
- Offline
- Moderator
-
- Ex Pilot, M.Sc, Ph.D
any sample for test
Did your set to your OS your local time ?
PilotLogic Architect and Core Programmer
Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0
any sample for test
procedure showOffset;
var
val: Integer;
begin
val:= GetLocalTimeOffset; // or any other with options
ShowMessage(val.ToString);
end;
Yes.Did your set to your OS your local time ?
On Ubuntu 20.04 same problem as on Ubuntu 21.04. So not problem in OS.
Function Now() and NowUTC() return 0 both.
Please Log in or Create an account to join the conversation.
- Vbxler
- Offline
- Junior Member
-
- Posts: 49
- Thank you received: 0
Xubuntu 20.04 and latest CT.
Please Log in or Create an account to join the conversation.
- Jan Roza
-
- Offline
- Junior Member
-
- Posts: 107
- Thank you received: 3
Operating Systems Windows 10 (64-bit) and virtual Linux Mint (64-bit)
Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0
Attachments:
Please Log in or Create an account to join the conversation.
- Vbxler
- Offline
- Junior Member
-
- Posts: 49
- Thank you received: 0
Attachments:
Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0
Local time: Пт 2021-03-12 12:16:24 MSK
Universal time: Пт 2021-03-12 09:16:24 UTC
RTC time: Пт 2021-03-12 09:16:24
Time zone: Europe/Moscow (MSK, +0300)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0
The project is on fire! We urgently need to do something!
Please Log in or Create an account to join the conversation.
- firliri
- Offline
- New Member
-
- Posts: 9
- Thank you received: 1
Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0
firliri wrote: Hi, did you test the ReReadLocalTime function ?
procedure TForm1.FormCreate(Sender: TObject);
var
s: string;
begin
s:= DateTimeToStr(Now)+' UTC:'+DateTimeToStr(NowUTC)+#13#10;
ReReadLocalTime;
s+= (' ReReading:'+#13#10+DateTimeToStr(Now)+' UTC:'+DateTimeToStr(NowUTC));
Label1.Caption:= s;
end;
But real time in my timezone 14:27:21
Attachments:
Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0

Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0
Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0
Attachments:
Please Log in or Create an account to join the conversation.
- Vital
-
Topic Author
- Offline
- Junior Member
-
- Posts: 61
- Thank you received: 0
There is no time to conduct more experiments. I remain until the delivery of the project on CT 7.0
Please Log in or Create an account to join the conversation.
- Sternas Stefanos
-
- Offline
- Moderator
-
- Ex Pilot, M.Sc, Ph.D
after today update from FPC SVN: 49001 more info
With the above source, I get this
On Fedora 33 with the same Local time with your local time (UTC+3)
Just download from SVN the file :
rtl\unix\timezone.inc
and replace the CT file:
codetyphon/fpcsrc/rtl/unix/timezone.inc
Rebuild ALL (FPC and Typhon)
We try hard to offer "On User Side Real Time Support", but sometime we want help ...
PilotLogic Architect and Core Programmer
Attachments:
Please Log in or Create an account to join the conversation.
- 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
-
- Offline
- Junior Member
-
- I do love ObjectPascal and WinApi
- Posts: 20
- Thank you received: 2
i did played abit with code and for windows this solution came out, maybe usfull or not, you decide, for me just fun to do

program Project1;
uses Windows, SysUtils, DateUtils;
// include winapi methods
function TzSpecificLocalTimeToSystemTime(lpTimeZoneInformation: PTimeZoneInformation; var lpLocalTime, lpUniversalTime: TSystemTime): BOOL; stdcall; external kernel32 name 'TzSpecificLocalTimeToSystemTime';
function SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation: PTimeZoneInformation; var lpUniversalTime, lpLocalTime: TSystemTime): BOOL; stdcall; external kernel32 name 'SystemTimeToTzSpecificLocalTime';
// convert local time to UTC
function DateTimeToUTC(const Local: TDateTime): TDateTime;
var
TZI: TTimeZoneInformation;
LocalTime,
UniversalTime: TSystemTime;
begin
GetTimeZoneInformation(TZI);
DateTimeToSystemTime(Local, LocalTime);
TzSpecificLocalTimeToSystemTime(@TZI, LocalTime, UniversalTime);
Result := SystemTimeToDateTime(UniversalTime);
end;
// convert UTC to local time
function UTCToLocalDateTime(const UTC: TDateTime): TDateTime;
var
TZI: TTimeZoneInformation;
LocalTime,
UniversalTime: TSystemTime;
begin
GetTimeZoneInformation(TZI);
DateTimeToSystemTime(UTC, UniversalTime);
SystemTimeToTzSpecificLocalTime(@TZI, UniversalTime, LocalTime);
Result := SystemTimeToDateTime(LocalTime);
end;
// example usage
var
Local,
UTC: TDateTime;
begin
Local := Now;
UTC := DateTimeToUTC(Local);
WriteLn('Local: ' + DateTimeToStr(Local));
WriteLn('UTC: ' + DateTimeToStr(UTC));
WriteLn('Offset: ' + IntToStr(SecondsBetween(Local, UTC) div 60 div 60));
ReadLn;
end.
Please Log in or Create an account to join the conversation.
- Matis A.
-
- Away
- Moderator
-
- Sternas Stefanos
-
- Offline
- Moderator
-
- Ex Pilot, M.Sc, Ph.D
Always we want your help,
it's a "critical factor" for us.
PilotLogic Architect and Core Programmer
Please Log in or Create an account to join the conversation.
- 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
-
- Offline
- Junior Member
-
- I do love ObjectPascal and WinApi
- Posts: 20
- Thank you received: 2
My source texts are unfortunately only suitable for windows.
Certainly there are methods in the existing libraries that achieve the same thing.
But I'm a little stubborn and usually go my own way.
I'll see what there is in the forum for questions.
If something appeals to me, especially with regard to windows and its api methods, i will tinker something.
If you are satisfied with what I offer, a small click on "thankyou" is enough to give me more incentive.
(For me, that reflects how well something is received or rejected.)
I don't want to violate forum rules, is there a kind of time limit until when you can answer a topic if you have perhaps found a better solution?
(I only picked this topic out because it was only a week old.)
Please forgive my spelling mistakes or the wrong sentence structure.
And please do not call me "Sir", call me KodeZwerg or in abbreviated form Kode.
Please Log in or Create an account to join the conversation.