本文主要是介绍秒换算成时分秒,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//秒换算成时:分:秒@Testpublic void secondToTime(){int one_minute = 60; int an_hour = 60*60;int secondTime = 4261;//需要转换的秒数int convertHour = secondTime/an_hour;int convertMinute = secondTime % an_hour /one_minute;int convertSecond = secondTime % an_hour % one_minute % one_minute;System.out.println(getFormatTime(convertHour,convertMinute,convertSecond));}public String getFormatTime(int... timeField){StringBuilder sbd = new StringBuilder();for(int i=0,length=timeField.length;i<length;i++){if(timeField[i]<10){sbd.append("0").append(timeField[i]).append(":");}else{sbd.append(timeField[i]).append(":");}}return sbd.deleteCharAt(sbd.length()-1).toString();}
结果 01:11:01
这篇关于秒换算成时分秒的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!