TimeSpan.Parse time format hhmmss

Parse the string to a DateTime value, then subtract it's Date value to get the time as a TimeSpan:

DateTime t = DateTime.ParseExact("124510", "HHmmss", CultureInfo.InvariantCulture);
TimeSpan time = t - t.Date;

This might help

using System;
using System.Globalization;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime d = DateTime.ParseExact("124510", "hhmmss", CultureInfo.InvariantCulture);

            Console.WriteLine("Total Seconds: " + d.TimeOfDay.TotalSeconds);

            Console.ReadLine();
        }
    }
}

Note this will not handle 24HR times, to parse times in 24HR format you should use the pattern HHmmss.

Tags:

C#

Timespan