Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说Java毫秒转时分秒「终于解决」,希望能够帮助你!!!。
import java.util.Scanner;
public class test {
public static void main ( String[] args ) {
Scanner input = new Scanner( System.in );
long n = input.nextLong( );
System.out.println( convertMillis( n ) );
}
public String convertMillis (long duration) {
if (duration != null) {
long hour = duration/ 3600;
long minute = (duration % 3600) / 60;
long second = (duration % 3600) % 60;
String hourStr = hour == 0 ? "00" : hour > 10 ? hour + "" : "0" + hour;
String minuteStr = minute == 0 ? "00" : minute > 10 ? minute + "" : "0" + minute;
String secondStr = second == 0 ? "00" : second > 10 ? second + "" : "0" + second;
return hourStr + ":" + minuteStr + ":" + secondStr;
}
return null;
}
}
今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。