How can a Timespan-Day last only for 8 Hours?

前端 未结 3 1565
我在风中等你
我在风中等你 2021-01-03 08:07

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:

<         


        
3条回答
  •  孤独总比滥情好
    2021-01-03 08:55

    You need to implement something like this:

    TimeSpan workday = new TimeSpan(8, 0, 0);
    int workdays = ts.Ticks / workday.Ticks
    TimeSpan rest = new TimeSpan(ts.Ticks % workday.Ticks)
    Response.Write(workdays  + "workday(s) and" + rest.ToString());
    

    Will write something like

    "3 workday(s) and 3:32"
    

提交回复
热议问题