How do i convert HH:MM:SS into just seconds using C#.net?

It looks like a timespan. So simple parse the text and get the seconds.

string time = "00:01:05";
double seconds = TimeSpan.Parse(time).TotalSeconds;

You can use the parse method on aTimeSpan.

http://msdn.microsoft.com/en-us/library/system.timespan.parse.aspx

TimeSpan ts = TimeSpan.Parse( "10:20:30" );
double totalSeconds = ts.TotalSeconds;

The TotalSeconds property returns the total seconds if you just want the seconds then use the seconds property

int seconds = ts.Seconds;

Seconds return '30'. TotalSeconds return 10 * 3600 + 20 * 60 + 30


TimeSpan.Parse() will parse a formatted string.

So

TimeSpan.Parse("03:33:12").TotalSeconds;

Tags:

C#

.Net

Datetime