StringToTimeSpan

        /// <summary>
        /// Converts a string time to a timespan.
        /// </summary>
        /// <param name="time">The time.</param>
        /// <returns>
        /// A timespan object.
        /// </returns>
        public static TimeSpan StringToTimeSpan(this string time)
        {
            TimeSpan timespan;
            var result = TimeSpan.TryParse(time, out timespan);
            return result ? timespan : new TimeSpan(0, 0, 0);
        }
Example:
string s = "22:03:34";

// Returns a TimeSpan object with 22 Hours, 3 Minutes and 34 Seconds
TimeSpan ts = s.StringToTimeSpan();  

Description

Converts a string to a timespan

Details

Double click on the code to select all.

 

;