C# Method to sum hh:mm data ???

夙愿已清 提交于 2019-12-19 19:54:33

问题


I want a method that will sum data that is string in the format hh:mm (time hours and minutes)

0:15 + 0:15 = 0:30


回答1:


Convert the strings to TimeSpans and then call the .Add method.

TimeSpan s1 = TimeSpan.Parse("0:15");
TimeSpan s2 = TimeSpan.Parse("0:45");

TimeSpan s3 = s1 + s2;

// not tested; should work.

Ref: http://msdn.microsoft.com/en-us/library/system.timespan.aspx



来源:https://stackoverflow.com/questions/2871557/c-sharp-method-to-sum-hhmm-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!