Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Feb : SNTP: Correct way to calculate time difference
| Subject: | SNTP: Correct way to calculate time difference |
| Posted by: | "Salvatore Besso" (s.bes..@mclink.it) |
| Date: | Sun, 27 Feb 2005 11:58:50 |
hello all,
I was wondering if the calculation that I am actually making to establish the
amount of correction after a synchronization is correct. I'm using a TIdSNTP
component and this is the code I'm using to calculate the difference after the
sync:
StartTime := Now;
if SNTP.SyncTime then
begin
EndTime := Now;
if EndTime < StartTime then
Diff := StartTime - EndTime
else Diff := EndTime - StartTime;
DecodeTime(Diff, Hour, Min, Sec, MSec);
Seconds := (MSec / 1000) + Sec + (Min * 60) + (Hour * 3600);
if EndTime < StartTime then
Seconds := -Seconds;
// Show correction in seconds in the form:
// Your clock has been corrected by %d seconds
// Seconds may be negative
Is this the correct way to calculate the difference or does any of the TIdSNTP
properties already hold this value after sync has been performed with success?
Thanks a lot
Salvatore