What is the best way to convert seconds into (Hour:Minutes:Seconds:Milliseconds) time?
Let's say I have 80 seconds, are there any specialized classes/techniques in .NET that would allow me to convert those 80 seconds into (00h:00m:00s:00ms) format like to DateTime or something?
For .NET > 4.0 you can use
or if you want date time format then you can also do this
For more you can check Custom TimeSpan Format Strings
The TimeSpan constructor allows you to pass in seconds. Simply declare a variable of type TimeSpan amount of seconds. Ex:
http://msdn.microsoft.com/en-us/library/system.timespan.fromseconds.aspx
I'd suggest you use the
TimeSpan
class for this.Outputs:
In VB.NET, but it's the same in C#:
to get total seconds
and to get datetime from seconds