将分钟转换为HH:MM ReportViewer

时间:2014-11-06 16:10:15

标签: c# time reportviewer rdlc

我有一份报告,我需要将持续时间值相加。 到目前为止,我有持续时间和总持续时间,以分钟为单位。 enter image description here

正如您在“DuraçãoTarefa”专栏中所看到的,我得到的第一个值是:HH:MM,以及总分钟数。

我需要什么: 如何将该值(1935)转换为HH:MM格式?

2 个答案:

答案 0 :(得分:1)

我打算建议使用DateTime.AddMinutes(),但这限制了你到24小时工作日。

以下内容应该通过一些简单的划分来实现:

    private void button27_Click(object sender, EventArgs e)
    {
        Debug.WriteLine(string.Format("{0}:{1}", 
                            GetHours(1935),
                            GetRemainderMinutes(1935)));
    }

    private int GetHours(int minutes)
    {
        // Get how many hours are contained in the total minutes
        return minutes / 60;
    }
    private object GetRemainderMinutes(int minutes)
    {
        // Get the remaining amount that couldn't be divided into hours.
        return minutes % 60;
    }

答案 1 :(得分:1)

这是我根据JoelC的建议得出的领域公式

= Format(Floor(Fields!TotalMins.Value / 60),“#0”)&“ h:”&Format(Fields!TotalMins.Value mod 60,“ 00”)&“ m”

需要地板,以便5.6不会给您6个小时的时间。其他格式仅用于显示目的。