[Q#5387371][A#5387398] How to convert minutes to Hours and minutes (hh:mm) in java
https://stackoverflow.com/q/5387371
I need to convert minutes to hours and minutes in java. For example 260 should be 4:20. can anyone help me how to do convert it.
Answer
https://stackoverflow.com/a/5387398
If your time is in a variable called t It couldn't get easier
APIzation
int hours = t / 60; //since both are ints, you get an int
int minutes = t % 60;
System.out.printf("%d:%02d", hours, minutes);
package com.stackoverflow.api;
public class Human5387398 {
public static void printMinutesInHHmm(int t) {
int hours = t / 60; //since both are ints, you get an int
int minutes = t % 60;
System.out.printf("%d:%02d", hours, minutes);
}
}
package com.stackoverflow.api;
/**
* How to convert minutes to Hours and minutes (hh:mm) in java
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/5387398">https://stackoverflow.com/a/5387398</a>
*/
public class APIzator5387398 {
public static void convertMinute(int t) throws Exception {
// since both are ints, you get an int
int hours = t / 60;
int minutes = t % 60;
System.out.printf("%d:%02d", hours, minutes);
}
}