I’m trying to solve this problem :
I’ve a large amount of minutes and I want to convert them into hours only, when I try with TimeSpan
, it always shows days and hours.
My example code :
double minutes = 2000 ;
TimeSpan hours = TimeSpan.FromMinutes(minutes);
label1.Text = hours.ToString(@"hh\:mm");
The output result is 09:20 but I wanted this result 33:20
How can I convert minutes to get exact numbers of hours ?
Converting between hours, minutes, and seconds using decimal time is relatively straightforward: time in seconds = time in minutes * 60 = time in hours * 3600. time in minutes = time in seconds / 60 = time in hours * 60. time in hours = time in minutes / 60 = time in seconds / 3600.
We know that 1 hour is divided into 60 minutes and 30 minutes is half of 60 minutes so we can say that 30 minutes is half of 1 hour.
1. Convert 45 minutes into hours. Therefore, 45 minutes = 45/60 hour = ¾ hour.
This code produces the 33:20
result you're asking:
double minutes = 2000;
TimeSpan ts = TimeSpan.FromMinutes(minutes);
var res = $"{(int)ts.TotalHours}:{ts.Minutes}";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With