Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Convert string to TimeSpan in C#
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { string span = "40:00"; TimeSpan ts = new TimeSpan(int.Parse(span.Split(':')[0]), // hours int.Parse(span.Split(':')[1]), // minutes 0); Console.WriteLine(ts); Console.WriteLine(Math.Round(ts.TotalHours) +":"+ts.Minutes.ToString("00") ); TimeSpan ts1=TimeSpan.Parse("05:30"); Console.WriteLine( (ts-ts1).TotalHours); } } }
run
|
edit
|
history
|
help
0
PrivateConstructorToCreateSingleObject
StackOverflowException
MyTime calculation
MegaWays3
first
Non-User input - Random Controlled - Guessing Game
hivix
Square Real Matrix
Two lines of Random number
hello world