# 第六章第二十五题（将毫秒数转换成小时数、分钟数和秒数）(Convert milliseconds to hours, minutes, and seconds) – 编程练习题答案

**6.25（将毫秒数转换成小时数、分钟数和秒数）使用下面的方法头，编写一个将毫秒数转换成小时数、分钟数和秒数的方法。

public static String convertMillis(long millis)

**6.25(Convert milliseconds to hours, minutes, and seconds)Write a method that converts milliseconds to hours, minutes, and seconds using the following header:

public static String convertMillis(long millis)

The method returns a string as hours:minutes:seconds. For example, convertMillis(5500) returns a string 0:0:5, convertMillis(100000)returns a string 0:1:40, and convertMillis(555550000) returns a string 154:19:10. Write a test program that prompts the user to enter a long integer for milliseconds and displays a string in the format of hours:minutes:seconds.

``````public class Ans6_25_page202 {
public static void main(String[] args) {
System.out.println(convertMillis(555550000));
System.out.println(convertMillis(100000));
System.out.println(convertMillis(5500));
}
public static String convertMillis(long millis) {
long totalSecond = millis / 1000;
long currentSecond = totalSecond % 60;
long totalMinute = totalSecond / 60;
long currentMinute = totalMinute % 60;
long totalHour = totalMinute / 60;