Java秒如何换算为天,小时,分钟,秒呢?
下文笔者讲述将java的秒转换为天,小时,分钟的方法分享,如下所示
实现思路: 使用简单的数学计算,即可得出相应的结果 1.计算天 2.计算小时 3.计算剩余分钟 4.计算剩余描述例:
方法1 : int infoCount = 82401; int day; int hour; int minute; day = infoCount / (24 * 60 * 60); infoCount -= day * 24 * 60 * 60; hour = infoCount / (60 * 60); infoCount -= hour * 60 * 60; minute = infoCount / 60; infoCount -= minute * 60; System.out.println(day + "天" + hour + "小时" + minute + "分钟" + infoCount + "秒"); 方法2 : long time = 82401; long day1 = time / 86400L; long hour1 = time % 86400L / 3600L; long minute1 = time % 3600L / 60L; long second1 = time % 60L; System.out.println(day1 + "天" + hour1 + "小时" + minute1 + "分钟" + second1 + "秒"); 方法3: int time2 = 82401; int day2 = time2 / 86400; int hour2 = (time2 / 3600) % 24; int minute2 = (time2 / 60) % 60; int second2 = time2 % 60; System.out.println(day2 + "天" + hour2 + "小时" + minute2 + "分钟" + second2 + "秒" );
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。