Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert minutes to days,hours,minutes

how to convert minutes into days hours and minutes in java ( we have a week here , 7 days )

 public String timeConvert(int time){
   String t = "";

   int h = 00;
   int m = 00;

  // h= (int) (time / 60);
  // m = (int) (time % 60);

  // if(h>=24) h=00;

   if((time>=0) && (time<=24*60)){
      h= (int) (time / 60);
      m = (int) (time % 60);
   }else if((time>24*60) && (time<=24*60*2)){
       h= (int) (time / (1440));
      m = (int) (time % (1440));
   }else if((time>24*60*2) && (time<=24*60*3)){
       h= (int) (time / (2880));
      m = (int) (time % (2880));
   }else if((time>24*60*3) && (time<=24*60*4)){
       h= (int) (time / (2880*2));
      m = (int) (time % (2880*2));
   }else if((time>24*60*4) && (time<=24*60*5)){
       h= (int) (time / (2880*3));
      m = (int) (time % (2880*3));
   }else if((time>24*60*5) && (time<=24*60*6)){
       h= (int) (time / (2880*4));
      m = (int) (time % (2880*4));
   }else if((time>24*60*6) && (time<=24*60*7)){
       h= (int) (time / (2880*5));
      m = (int) (time % (2880*5));
   }

   t =h+":"+m ;
   return t;
 }

I tried this but it dont work

thanks

like image 661
Eddinho Avatar asked May 01 '10 18:05

Eddinho


People also ask

How do you convert minutes to hours and days?

To convert a minute measurement to a day measurement, divide the time by the conversion ratio. The time in days is equal to the minutes divided by 1,440.

What is the formula to convert minutes to hours?

To convert from minutes to hours, divide the number of minutes by 60. For example, 120 minutes equals 2 hours because 120/60=2.

How do I convert minutes to days in Excel?

=CONVERT(B5,"mn","day") Then, press ENTER. Excel will return the output.


1 Answers

A shorter way. (Assumes time >= 0)

 public String timeConvert(int time) { 
   return time/24/60 + ":" + time/60%24 + ':' + time%60;
 }
like image 150
Peter Lawrey Avatar answered Sep 19 '22 09:09

Peter Lawrey