Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Problem mit Countdown (https://www.delphipraxis.net/96882-problem-mit-countdown.html)

Adrian112 1. Aug 2007 09:17


Problem mit Countdown
 
Hallo,
ich programmiere gerade für einen Bekannten einen Countdown bis zum 3.8.2010. Mit diesem Quelltext zeige ich die Tage, Stunden, und Minuten bis zum 3.8.2010 an.
Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Days.Caption := IntToStr(DaysBetween(StrToDate(DateToStr(Now)),StrToDate('03.08.2010')));
Hours.Caption := IntToStr(23 - HoursBetween(StrToTime(TimeToStr(Now)),StrToTime('0')));
Minutes.Caption := IntToStr(59 - MinutesBetween(StrToTime(TimeToStr(Now)),StrToTime(IntToStr((23 - StrToInt(Hours.Caption))))));
// Hier sollen die Angaben für Sekunden rein
end;
Wie könnte ich jetzt dafür sorgen dass die verbleibenden Sekunden auch angezeigt werden? :wall: Ich bring dass einfach net hin :wall:

s-off 1. Aug 2007 10:12

Re: Problem mit Countdown
 
Hallo,

DateUtils kennt auch
Delphi-Quellcode:
function SecondsBetween(const ANow, AThen: TDateTime): Int64;
begin
  Result := Trunc(SecondSpan(ANow, AThen));
end;
Edit: Änderung als neuen Post, damit Du sie net übersiehst ;)

Adrian112 1. Aug 2007 10:19

Re: Problem mit Countdown
 
Klappt nicht, denn es zeigt mir die gesammten Sekunden bis um 3.8.2010 an, ich will aber die restsekunden bis zur nächsten Minute

chrisw 1. Aug 2007 10:24

Re: Problem mit Countdown
 
Einfacher wäre noch:
Delphi-Quellcode:
function CountDownStr : String;
const TheDate = '3.8.2010';
var h,m,s,ts : Word;
begin
  DecodeTime(now,h,m,s,hs);
  Result := IntToStr(DaysBetween(now,StrToDate(TheDate))) + ' Tage' + #13#10 +
            IntToStr(h) + ' Stunden' + #13#10 +
            IntToStr(m) + ' Minuten' + #13#10 +
            IntToStr(s) + ' Sekunden' + #13#10 +
            IntToStr(ts) + ' Tausendstel' + #13#10 +  );
end;

Adrian112 1. Aug 2007 10:28

Re: Problem mit Countdown
 
Danke, genau so hab ich mir das vorgestellt!!! :thumb:

s-off 1. Aug 2007 10:29

Re: Problem mit Countdown
 
Probier's mal so

Delphi-Quellcode:
Procedure TForm1.Timer1Timer(Sender: TObject);
Var
   dtTargetDate: TDateTime;
   dtDiff: TDateTime;
Begin
   //Das Zieldatum
   dtTargetDate := StrToDateTime('03.08.2010 00:00:00');

   //Differenz zw. Zieldatum und jetzt
   dtDiff := dtTargetDate - Now;

   //Zeitelemente in den Labels darstellen
   lblJahre.Caption := Format('Noch %s Jahre,', [FormatDateTime('yy', dtDiff)]);
   lblTage.Caption := Format('%s Tage,', [FormatDateTime('dd', dtDiff)]);
   lblStunden.Caption := Format('%s Stunden,', [FormatDateTime('hh', dtDiff)]);
   lblMinuten.Caption := Format('%s Minuten,', [FormatDateTime('nn', dtDiff)]);
   lblSekunden.Caption := Format('und %s Sekunden bis zum %s', [FormatDateTime('ss', dtDiff), DateTimeToStr(dtTargetDate)]);
End;

Adrian112 1. Aug 2007 10:34

Re: Problem mit Countdown
 
Danke, so gehts auch :thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:41 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