Parse string to TimeSpan
using System;
public class Example
{
public static void Main()
{
string value = null;
TimeSpan interval;
value = "6";
if (TimeSpan.TryParseExact(value, "%d", null, out interval))
Console.WriteLine("{0} --> {1}", value, interval.ToString("c"));
else
Console.WriteLine("Unable to parse '{0}'", value);
}
}
//6 --> 6.00:00:00
Related examples in the same category