以小时为单位的总和天数C# [英] Sum days in hours timespan C#

查看:96
本文介绍了以小时为单位的总和天数C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发软件来查询MySql服务器上的两个日期。有了这两个日期,我减去并显示该值。问题是显示是1.13:04:28.09933。格式为dd.hh:mm:ss:mmmmmm。我希望他把时间添加到小时。示例:1天= 24小时,然后1.13:04:28.09933 = 37:04:28(仅限hh:mm:ss)



我有什么试过:



Hi,
I am developing software to query two dates on the MySql server. With these two dates I subtract and display the value. The problem is that the display is 1.13: 04: 28.09933. The format is in dd.hh: mm: ss: mmmmmm. I want him to add the day to the hours. Example: 1 day = 24 hours, then 1.13: 04: 28.09933 = 37:04:28 (only hh: mm: ss)

What I have tried:

MessageBox.Show(tsystem.ToString(@"hh\:mm\:ss"))

推荐答案

标准 [ ^ ]也不是自定义TimeSpan格式字符串 [ ^ ]提供了一个选项。您需要手动构造字符串:

Neither the standard[^] nor the custom TimeSpan format strings[^] provide an option to do that. You'll need to construct the string by hand instead:
MessageBox.Show(string.Format("{0:#,##0}:{1:mm}:{1:ss}", Math.Truncate(tsystem.TotalHours), tsystem));


这篇关于以小时为单位的总和天数C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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