《java语言程序设计》习题5.25

来源:互联网 发布:微软office for mac 编辑:程序博客网 时间:2024/05/22 07:57

public static String convertMillis(long millis)

使用下面方法,编写一个将毫秒转换成小时数、分钟数和秒数的方法.

class MyDate {public static String convertMills(long millis) {long totalSeconds = millis / 1000;long nowSeconds = totalSeconds % 60;long totalMinutes = totalSeconds / 60;long nowMinutes = totalMinutes % 60;long totalHour = totalMinutes / 60;long nowHour = totalHour;return nowHour + ":" + nowMinutes + ":" + nowSeconds;}}class Test10 {public static void main(String[] args) {System.out.print(MyDate.convertMills(555550000));}}



1 0
原创粉丝点击