如何在java中将分钟转换为小时和分钟(hh:mm) [英] How to convert minutes to Hours and minutes (hh:mm) in java
本文介绍了如何在java中将分钟转换为小时和分钟(hh:mm)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在java中将分钟转换为小时和分钟。例如260应该是4:20。任何人都可以帮助我如何转换它。
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.
推荐答案
如果你的时间在一个名为 t的变量中
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);
它变得不容易
这篇关于如何在java中将分钟转换为小时和分钟(hh:mm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文