C# 对 hh:mm 数据求和的方法 ???

发布于 2024-09-02 02:23:15 字数 71 浏览 2 评论 0原文

字符串数据求和的方法

我想要一种对格式为 hh:mm(时间小时和分钟) 0:15 + 0:15 = 0:30 的

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩一世无双 2024-09-09 02:23:15

将字符串转换为 TimeSpans,然后调用 .Add 方法。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文