到HH:MM:SS到rdlc的总时间

本文关键字:时间 SS HH MM rdlc | 更新日期: 2023-09-27 18:08:11

这是我现在的代码。以下代码使用表达式计算我的rdlc中的总时间。

(Sum(System.TimeSpan.Parse(Fields!Number_of_Hours.Value).Hours)) &":"&(Sum(System.TimeSpan.Parse(Fields!Number_of_Hours.Value).Minutes))

此代码显示总小时和总分钟。

111:217

我想看到的是这个…这可能吗?

113:37

到HH:MM:SS到rdlc的总时间

这有点不清楚,但我想你是说你有一个输入时间的字符串,格式像111:217,其中分钟组件可以>= 60。您希望以hh:mm显示,其中分钟组件为<60 .

TimeSpan.Parse()似乎不喜欢您输入的格式。它期待会议纪要。60小时<24. 您必须使用TimeSpan构造函数。试试下面的代码:

string input = "111:217";
// Split the string into pieces on ":"
string[] parts = input.Split(':');
// Create a TimeSpan from our pieces
int hours = Int32.Parse(parts[0]);
int minutes = Int32.Parse(parts[1]);
TimeSpan time = new TimeSpan(hours, minutes, 0);
// Show the time formatted
string formatted = time.ToString(@"hh':mm");
Console.WriteLine(formatted);   
// Show the total time in minutes
double totalMinutes = time.TotalMinutes;
Console.WriteLine(totalMinutes);

下面是显示代码工作的提琴:https://dotnetfiddle.net/iEeA6J