Quantcast
Channel: User Federico klez Culloca - Stack Overflow
Viewing all articles
Browse latest Browse all 505

Answer by Federico klez Culloca for How to convert minutes to Hours and Minutes (hh:mm) in Java?

$
0
0

If your time is in a variable called t :

int hours   = t / 60;   // since both are ints, you get an intint 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 etc.

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.


Viewing all articles
Browse latest Browse all 505

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>