Parse string to TimeSpan in CSharp
Description
The following code shows how to parse string to TimeSpan.
Example
using System.Threading;
using System;/*w w w . java 2 s .c o m*/
using System.Globalization;
public class MainClass
{
public static void Main(String[] argv){
string[] values = { "000000006", "12.12:12:12.12345678",
"6", "6:12", "6:12:14", "6:12:14:45",
"6.12:14:45", "6:12:14:45.3448",
"6:12:14:45,3448", "6:34:14:45" };
foreach (string value in values)
{
TimeSpan interval = TimeSpan.Parse(value);
Console.WriteLine("{0} --> {1}", value, interval);
}
}
}
The code above generates the following result.