C#方法求和hh:mm数据 [英] C# Method to sum hh:mm data ???

查看:214
本文介绍了C#方法求和hh:mm数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一种方法,将以hh:mm(时间和分钟)的格式汇总字符串数据。

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

0:15 + 0:15 = 0:30

推荐答案

将字符串转换为 TimeSpan ,然后调用。添加方法。

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.

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

这篇关于C#方法求和hh:mm数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆