如何在 C# 中仅添加时间

发布于 2024-09-16 04:38:12 字数 243 浏览 10 评论 0原文

我需要对我的水晶报告进行计算。

在报告中,会有像这样的时间(以小时:分:秒为单位)..

00:12:34

00:52:12

23:19:56

等等..

我需要将它们加在一起,以便..结果将是

Hr:min:ss

Hr 可能超过 100..

但无法更改为 day

如何实现这一点?

多谢..

I need to do a calculation for my crystal report.

In report, there will be Times(in Hour:Min:Sec)like this..

00:12:34

00:52:12

23:19:56

and so on..

I need to add them together so that..results will be

Hr:min:ss

Hr may be more than 100..

but can't change to day

How to achieve that?

Thanks a lot..

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

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

发布评论

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

评论(2

腹黑女流氓 2024-09-23 04:38:12

像这样查找 TimeSpan.Parse 方法。

var t1 = TimeSpan.Parse("00:12:34");
var t2 = TimeSpan.Parse("00:52:12");
var t3 = TimeSpan.Parse("23:19:56");

var result = t1 + t2 + t3

Console.WriteLine("Total time is {0} Hours {1} Mins {2} secs", 
result.Days * 24 + result.Hours, result.Minutes, results.Seconds);

Look up the TimeSpan.Parse method like this.

var t1 = TimeSpan.Parse("00:12:34");
var t2 = TimeSpan.Parse("00:52:12");
var t3 = TimeSpan.Parse("23:19:56");

var result = t1 + t2 + t3

Console.WriteLine("Total time is {0} Hours {1} Mins {2} secs", 
result.Days * 24 + result.Hours, result.Minutes, results.Seconds);
星星的轨迹 2024-09-23 04:38:12

如果你得到 hh:mm:ss,那么这就会很容易:

hh x 60 x 60 + mm x 60 + ss

然后从中得到小时、分钟和秒。

如果您获取 DateTime 对象,那么您可以获得小时、分钟并将它们转换为秒,并使用与上述相同的技术。

It you are getting hh:mm:ss only then this will be easy:

hh x 60 x 60 + mm x 60 + ss

and then get hours, mins and seconds from it.

If you are getting DateTime object then you can get hours, mins and convert them to seconds and use same technique as above.

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