Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
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
Please
log in
to post a comment.
test string format with curly braces as a value
DateTime.Now.Date
HMS abstract
Intuit // C# // Lecture_4 // Laba_#1
Intuit // C# // listing_4.8 (while)
String Factorial Sorter
linq jean by Fausto
Least Common Multiple of 2 or more numbers.
Test
Пример применения необязательных аргументов
stackse - search stackoverflow differently
Please log in to post a comment.