C#
[C#] TimeSpan 24시간 이상 파싱
Minius
2021. 4. 15. 16:02
반응형
24시간 이상 파싱이 안될 때
24시간을 파싱해서 더 할 수 없다.
시간은 0~23까지만 유효하기에, 24로하면 24일로 파싱된다고 한다.
이에 대한 해결책
24시간이 넘는 시간은 아래와 같이 파싱한다.
string span = "35:15";
TimeSpan ts = new TimeSpan(int.Parse(span.Split(':')[0]), // hours
int.Parse(span.Split(':')[1]), // minutes
0); // seconds
출처
stackoverflow.com/questions/2728321/how-to-parse-string-with-hours-greater-than-24-to-timespan
How to parse string with hours greater than 24 to TimeSpan?
How to parse string like 30:15 to TimeSpan in C#? 30:15 means 30 hours and 15 minutes. string span = "30:15"; TimeSpan ts = TimeSpan.FromHours( Convert.ToDouble(span.Split(':')[0])). Add(Tim...
stackoverflow.com