AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

exchange elapsed time between Clients

Ein Thema von sdean · begonnen am 24. Jun 2010 · letzter Beitrag vom 25. Jun 2010
Antwort Antwort
sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#1

exchange elapsed time between Clients

  Alt 24. Jun 2010, 15:17
Delphi-Version: 2005
Hi , i've 2 Clients " 2 Machines in my network " and a Server i use the following procedure to calc the elapsed time :

Delphi-Quellcode:
procedure TForm1.ElapsedTimeTimer(Sender: TObject);
var
    s: string;
    TotalTime: TDateTime;
    DLTimes: Double;
    Hh, Mh, Sec, MSec: Word;
begin
  TotalTime:= Now-FStartTime;
  DecodeTime(TotalTime, hH, Mh, Sec, MSec);
  Sec := Sec + Mh * 60 + hH * 3600;
   DLTimes := Sec + MSec / 1000;
  s:=Format('%2d:%2d:%2d', [sSec div 3600, (Sec div 60) mod 60, Sec mod 60]);
  label1.Caption:=FormatDateTime('"elapsed time : " hh:nn:ss', StrToTime(s));
end;
Let's suppose that ClientA's elapsed time is : 00:20:00 here when i transfer this elapsed time value to ClientB this letter elapsed time will become 12:20:00

so why 12:20:00 and not 00:20:00 ?



P.S : i use Indy
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.008 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#2

AW: exchange elapsed time between Clients

  Alt 24. Jun 2010, 15:30
I guess on the one machine the date time format of windows is set to 24h format while the other is set to 12h format (if i remember 12:20 is the 12h format for 20 minutes after midnight)
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#3

AW: exchange elapsed time between Clients

  Alt 24. Jun 2010, 15:58
thank you Stevie , But the 2 Machines' time format is 12h .
  Mit Zitat antworten Zitat
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#4

AW: exchange elapsed time between Clients

  Alt 24. Jun 2010, 16:53
The elapsed time could be greater than 12 or 24 hours.
I suggest to format the time like this:
Delphi-Quellcode:
function GetElapsedTimeAsString(t : Double; WithMS:Boolean=False):string;
const
  HOURS_PER_DAY = 24.0;
  MINUTES_PER_HOUR = 60.0;
  SECONDS_PER_MINUTE = 60.0;
  MS_PER_SECOND = 1000.0;
var
  Hh, Mh, Sec, MSec: integer;
  sign : string;
begin
  if t < 0.0 then
  begin
    t := -t;
    sign := '-';
  end
  else
    sign := '';

  t := t * HOURS_PER_DAY;
  Hh := Trunc(t);
  t := (t - Hh) * MINUTES_PER_HOUR;
  Mh := Trunc(t);
  t := (t - Mh) * SECONDS_PER_MINUTE;
  Sec := Trunc(t);
  t := (t - Sec) * MS_PER_SECOND;
  MSec := Trunc(t);

  if WithMS then
     result := sign + Format('%2.2d%s%2.2d%s%2.2d.%3.3d', [Hh, TimeSeparator,Mh, TimeSeparator,sec,Msec])
   else
     result := sign + Format('%2.2d%s%2.2d%s%2.2d', [Hh, TimeSeparator,Mh, TimeSeparator,sec]);
end;

procedure TForm1.ElapsedTimeTimer(Sender: TObject);
begin
  label1.Caption:='"elapsed time : " ' + GetElapsedTimeAsString(Now-FStartTime);
end;
The function GetElapsedTimeAsString() can format negative timespans, too.
Andreas
  Mit Zitat antworten Zitat
sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#5

AW: exchange elapsed time between Clients

  Alt 24. Jun 2010, 23:36
thank you shmia , But when i transfer elapsed time from a Client to an other the result will be as follows :

ClientA's elapsed time is : 00:20:00 when i trabsfer it to ClientB it will be : 968484:20:00

is there any issue with it ?!
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.008 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#6

AW: exchange elapsed time between Clients

  Alt 25. Jun 2010, 06:49
How do you transfer it? Send the float value or format it to let's say UTC?
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz