Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting minutes to hours only

Tags:

c#

timespan

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 ?

like image 734
D.Iple Avatar asked Jan 15 '18 09:01

D.Iple


People also ask

How do you convert minutes to hours and seconds?

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.

How can I turn 30 minutes into one hour?

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.

How do you write 45 minutes in hours?

1. Convert 45 minutes into hours. Therefore, 45 minutes = 45/60 hour = ¾ hour.


1 Answers

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}";
like image 90
CodeFuller Avatar answered Sep 20 '22 01:09

CodeFuller