Autor Beitrag
Orothred
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 86


C# (VS 2005)
BeitragVerfasst: Do 13.09.07 11:12 
hab in mein Projekt Kopfrechentrainer (siehe Freeware-Bereich) eine zeitmessung eingebaut. allerdings bekomme ich die zeit in einem format ähnlich diesem: 00:00:23.234234

wie kann ich das format ändern, das es nur die benötigten sekunden anzeigt?


Moderiert von user profile iconChristian S.: Zweite Frage entfernt, siehe [url=www.c-sharp-forum.de...6312.html]hier[/url]
Moderiert von user profile iconChristian S.: Topic aus C# - Die Sprache verschoben am Do 13.09.2007 um 11:27


Zuletzt bearbeitet von Orothred am Do 13.09.07 11:21, insgesamt 1-mal bearbeitet
bd.cole
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 46

Win XP, Vista
C# (VS 2005)
BeitragVerfasst: Do 13.09.07 11:18 
ausblenden C#-Quelltext
1:
2:
3:
4:
TimeSpan ts = stopWatch.Elapsed;  

labelTime.Text = String.Format("{0:00}:{1:00}:{2:00}",   
    ts.Hours, ts.Minutes, ts.Seconds);

so müsste es gehen. Oh verlesen, dachte du willst nur bis sekunden anzeigen
Orothred Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 86


C# (VS 2005)
BeitragVerfasst: Do 13.09.07 11:29 
ok, danke, das hat schonmal funktioniert.

Moderiert von user profile iconChristian S.: Zweite Frage entfernt, siehe [url=www.c-sharp-forum.de...6312.html]hier[/url]
bd.cole
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 46

Win XP, Vista
C# (VS 2005)
BeitragVerfasst: Do 13.09.07 11:55 
Falls du die Zeit ohne Minuten anzeigen willst, also dass er alles in Sekunden umrechnet müsste das hier gehen:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
private int Zeitspanne(DateTime start, DateTime end){
TimeSpan zeit = new TimeSpan();
zeit = end - start;
int mymilli = zeit.Milliseconds;
int myseconds = (zeit.Seconds * 1000);
int myminutes = (zeit.Minutes * 1000 * 60);
int myhours = (zeit.Hours * 1000 * 60 * 60);
return((mymilli + myseconds + myminutes + myhours)/1000);
}
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Do 13.09.07 12:35 
Oder einfach (int)TimeSpan.TotalSeconds.

PS: Deine erste Zuweisung macht wenig Sinn, wenn du den Wert in der nächsten Zeile direkt überschreibst. Und die Millisekunden-Variable und die 1000er-Multiplikationen/Divsionen (und diverse Klammern) brauchst du ebenfalls nicht ;) .