本文介绍了将TimeSpan转换为分钟和秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要解决两个问题.

首先,我想将TimeSpan转换为以下格式的分钟和秒:
如果是54分32秒,则它应该是54.32(两倍).

之后,我需要从totalDuration中减去值8.0.

我的代码如下所示:

public double TotalDuration结果,{结果,获取搜索结果{INT分钟;结果,INT秒;结果,时间跨度持续时间=结束时间 - 开始时间;结果,totalDuration = Convert.ToDouble(duration.TotalMinutes(分,秒))-8;
返回totalDuration;
}
设置{totalDuration = value; }
}


其次,我想对此值进行四舍五入.如果秒值大于30,则将其四舍五入.如果秒值小于30,则将其四舍五入.

例如:
如果值为54.32,则将其四舍五入为55.
如果值为54.20,则将其四舍五入为54.

Hi,

I need help with two issues.

Firstly, I want to convert a TimeSpan to minutes and seconds in this format:
If it is 54min 32sec, then it should be 54.32 (as double).

After which I need to subtract the value 8.0 from the totalDuration

This is how my code looks like:

public double TotalDuration
        {
            get
            {
                int minutes;
                int seconds;
                TimeSpan duration = EndTime - StartTime;
                totalDuration = Convert.ToDouble(duration.TotalMinutes(minutes,seconds)) - 8;
                return totalDuration;
            }
            set { totalDuration = value; }
        }


Secondly, I want to do a rounding to this value. If the seconds value is more than 30, round it up. If a seconds value is less than 30, round it down.

For example:
If a value is 54.32, round it up to 55.
If a value is 54.20, round it down to 54.

请指导我.我对此很陌生.谢谢.

Please guide me through this. I'm very new to this. Thanks.

推荐答案


这篇关于将TimeSpan转换为分钟和秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 15:43