I need to convert minutes to hours and minutes in java. For example 260 minutes should be 4:20. can anyone help me how to do convert it.
There are 60 minutes in 1 hour. To convert from minutes to hours, divide the number of minutes by 60. For example, 120 minutes equals 2 hours because 120/60=2.
mport java. util. Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int days=24; int hours = 60; int mins=60; int res=days*hours*mins; System.
If your time is in a variable called t
int hours = t / 60; //since both are ints, you get an int int minutes = t % 60; System.out.printf("%d:%02d", hours, minutes);
It couldn't get easier
Addendum from 2021:
Please notice that this answer is about the literal meaning of the question: how to convert an amount of minute to hours + minutes. It has nothing to do with time, time zones, AM/PM...
If you need better control about this kind of stuff, i.e. you're dealing with moments in time and not just an amount of minutes and hours, see Basil Bourque's answer below.
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