Shaitan00 Posted September 11, 2005 Posted September 11, 2005 Given a Double value (dElapsedTime) which represents the amount of SECONDS elasped - what I need is to represent this value in the form hh:mm:ss (hour:minute:second). Problem is I have noticed TimeSpan doesn't support such formatting (TimeSpan is d.hh:mm:ss, I don't want the "Days" - this is used to caluclate the amount oh hours a project was worked on for billing purposes). Also - DateTime doesn't seem to be able to represent this correctly - I can get it in the hh:mm:Ss format (.ToString("HH:mm:ss");) BUT this represent a DateTime so if the HOURS go over 24hours it starts back at 0 instead of counting... (obviously this won't work) So I need a way to convert SECONDS into HH:MM:SS - any clues/hints/help? Worst-Case-Scenario I need to write a function that takes (double) and returns (string) and does the conversion, I just don't have a CLUE how to accomplish this task manually. Thanks, Quote
Administrators PlausiblyDamp Posted September 11, 2005 Administrators Posted September 11, 2005 Bit rough and ready (plus I've hardcoded the return format which is generally a bad idea) but the following should give you a starting point... private string Test(int seconds) { TimeSpan ts = new TimeSpan(0,0,0, seconds, 0); int Hours = (int) ts.TotalHours; return string.Format("{0}:{1}:{2}", Hours,ts.Minutes, ts.Seconds); } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.