哪有时间跨度日最后只剩下8小时? [英] How can a Timespan-Day last only for 8 Hours?

查看:120
本文介绍了哪有时间跨度日最后只剩下8小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经保存在分钟的时间,并希望有一个输出1每天5小时30分钟。目前,我添加了分钟一个时间跨度,做这样的事情:

I have saved a duration in minutes and want to have an output "1 day 5 hours 30 minutes". Currently i add the minutes to a Timespan and do something like this:

TimeSpan ts = new TimeSpan(0,0,1800, 0);
Response.Write(ts.Days + "day(s) " + ts.Hours + " hour(s)" + ts.Minutes + " minutes");



但现在我只能在每天的工作时间的兴趣。所以当时间跨度的持续时间为27个小时不应该创建输出1天3小时。我想有3天3小时。

But now i am only interested in the working-hours of a day. So when the duration of the TimeSpan is 27 Hours it should not create the output "1 Day 3 Hours". I want to have "3 Days 3 Hours".

是否有可能一个简单的方法来做到这一点的时间跨度对象吗?是否有可能改变的时间跨度的默认行为?还是我编程我自己的自定义时间跨度级?

Is there maybe an easy way to do that with the Timespan object? Is it possible to change the default behaviour of the TimeSpan? Or do i have to program my own custom Timespan-Class?

THX
cpt.oneeye

Thx cpt.oneeye

推荐答案

您可以简单地使用:

(int)(ts.TotalHours / 8)

而不是 ts.Days ?然后使用

(((int)ts.TotalHours) % 8)

而不是 ts.Hours

这篇关于哪有时间跨度日最后只剩下8小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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