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