Autor Beitrag
pascalsv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133

Win XP Prof. SP2 / Windows 7
Visual Studio 2008 / Silverlight 3 / Silverlight 4 Beta
BeitragVerfasst: Mo 14.08.06 14:31 
Hallo zusammen,

ich nutze eine Funktion hier aus dem Forum (dem Entwickler sei Dank!), mit der ich Sekunden in eine sprechende Stunden-Minuten-Sekunden-Azeige umwandle. Leider sind die entsprechenden Werte nicht immer zweistellig, d.h. bis 9 fehlt die führende Null (die ich gerne hätte).

Wie könnte ich den Code ändern, um das zu erreichen?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function TfMain.SecToTime(Sec: Integer): string;
var
   H, M, S: string;
   ZH, ZM, ZS: Integer;
begin
   ZH := Sec div 3600;
   ZM := Sec div 60 - ZH * 60;
   ZS := Sec - (ZH * 3600 + ZM * 60) ;
   H := Format('%2d', [ZH]);
   M := Format('%2d', [ZM]);
   S := Format('%2d', [ZS]);
   Result := H + ':' + M + ':' + S;
end;


Ich hatte gedacht, %2d würde diese Aufgabe übernehmen, aber Fehlanzeige. Warum geht es nicht?

Pascal
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mo 14.08.06 14:39 
Nee, das geht mit '%.2d'

_________________
Na denn, dann. Bis dann, denn.
pascalsv Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133

Win XP Prof. SP2 / Windows 7
Visual Studio 2008 / Silverlight 3 / Silverlight 4 Beta
BeitragVerfasst: Di 15.08.06 12:18 
Jepp, das funktioniert!

Vielen Dank!

Pascal