00:00:00 can't be displayed as hh:mm:ss though. You need HH:mm:ss for that.
If you need to show total hours this method won't work if the TimeSpan exceeds 24 hours.
If this is an issue you can always format your string the hard way
TimeSpan s = dateTimeB - dateTimeA;
string time = ((int)s.TotalHours).ToString().PadLeft(2, '0') +":" + s.Minutes.ToString().PadLeft(2, '0') + ":" + s.Seconds.ToString().PadLeft(2, '0');
On Sat, 05 Aug 2006 17:02:02 +0200, Muhammad Mosa <Mu**********@discussions.microsoft.comwrote:
I think you can do it like this:
TimeSpan ts = new TimeSpan(23,40,3);
DateTime d = new DateTime(ts.Ticks);
string time = d.ToString("hh:mm:ss");
--
Happy coding!
Morten Wennevik [C# MVP]