|
@@ -118,4 +118,40 @@ public class TimeUtil {
|
|
|
return before.toString();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static String changeTimeFormat(int seconds) {
|
|
|
+ if (seconds > 0 && seconds < 60) {//小于1分钟
|
|
|
+ return seconds + "秒";
|
|
|
+ } else if (seconds >= 60 && seconds < 3600) {//大于等于1分钟小于1小时
|
|
|
+ int changeM = (int) Math.floor(seconds / 60);//整分钟数
|
|
|
+ int surplusM = (int) Math.floor(seconds % 60);//余下的秒数
|
|
|
+ if (surplusM > 0) {//余数不为0秒
|
|
|
+ return changeM + "分" + surplusM + "秒";
|
|
|
+ } else {//整分钟,没有余数
|
|
|
+ return changeM + "分";
|
|
|
+ }
|
|
|
+ } else if (seconds >= 3600) {//大于1小时
|
|
|
+ int changeH = (int) Math.floor(seconds / 3600);//整小时数
|
|
|
+ int surplusH = (int) Math.floor(seconds % 3600);//剩下的秒数
|
|
|
+ if (surplusH >= 60) {//余数大于大于1分钟
|
|
|
+ int changeM = (int) Math.floor(surplusH / 60);
|
|
|
+ int surplusM = (int) Math.floor(surplusH % 60);
|
|
|
+ if (surplusM > 0) {//余数大于0
|
|
|
+ return changeH + "小时" + changeM + "分" + surplusM + "秒";
|
|
|
+ } else {//整分钟,没有余数
|
|
|
+ return changeH + "小时" + changeM + "分";
|
|
|
+ }
|
|
|
+ } else if (surplusH < 60 && surplusH > 0) {//余数小于1分钟,大于0秒
|
|
|
+// int surplusM = (int) Math.floor(surplusH % 1);
|
|
|
+ return changeH + "小时" + surplusH + "秒";
|
|
|
+ } else {
|
|
|
+ return changeH + "小时";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "暂无数据";
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println(changeTimeFormat(3601));
|
|
|
+ }
|
|
|
}
|