Java将分钟转换为小时分钟

时间:2015-01-09 09:25:43

标签: java

我需要在java中将分钟转换为小时和分钟,所以我这样做 的 的java:

long minutes = offer.getDuration();
long hours = minutes / 60;
long minnutesRemaining = minutes % 60;
trainOffer.setDuration(hours+"h"+minnutesRemaining);

输出:

minutes = 129
hours = 2
minnutesRemaining = 9

我该如何处理minnutesRemaining = 09

1 个答案:

答案 0 :(得分:2)

使用String.format格式化输出:

System.out.println(String.format("%02d", minnutesRemaining ));