需要在C#应用程序中进行计数,在SLA中以分钟为单位,以以下格式显示:
N working days, N working hours, N working minutes
当前代码仅显示小时:分钟格式:
TimeSpan spWorkMin = TimeSpan.FromMinutes(12534);
string workHours = string.Format("{0}:{1:00}", (int)spWorkMin.TotalHours, spWorkMin.Minutes);
Console.WriteLine(workHours);
答案 0 :(得分:1)
下面是显示天数,小时数和分钟数的代码:
TimeSpan spWorkMin = TimeSpan.FromMinutes(12534);
string workHours = $"{spWorkMin.Days} working days, {spWorkMin.Hours} working hours, {spWorkMin.Minutes} working minutes";
Console.WriteLine(workHours);
答案 1 :(得分:1)
我不确定您要实现什么目标,但是在通常的一天里,您会获得3个工作日。
var numberOfDays = minutes/60/24;
var numberOfBusinessDays = numberOfDays/3;
var numberOfBusinessHours = (numberOfBusinessDays - Math.Truncate(numberOfBusinessDays))*24;
var numberOfBusinessMinutes = (numberOfBusinessHours - Math.Truncate(numberOfBusinessHours)*60;
然后您可以截取所有结果中的小数部分
int numberOfBusinessDaysToInt = Math.Truncate(numberOfBusinessDays);
int numberOfBusinessHoursToInt = Math.Truncate(numberOfBusinessHours);
int numberOfBusinessMinutesToInt = Math.Truncate(numberOfBusinessMinutes);