2023-08-01 15:33:17 +08:00
|
|
|
|
package com.zhgd.xmgl.util;
|
|
|
|
|
|
|
2024-02-01 10:24:58 +08:00
|
|
|
|
import java.util.Objects;
|
2024-01-08 11:18:39 +08:00
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
2023-08-01 15:33:17 +08:00
|
|
|
|
public class TimeUtil {
|
2023-09-19 18:36:09 +08:00
|
|
|
|
/**
|
2024-02-20 14:26:43 +08:00
|
|
|
|
* 获取时分秒显示,格式:548h17min31s
|
2023-09-19 18:36:09 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @param second
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2023-08-01 15:33:17 +08:00
|
|
|
|
public static String toHourMinSecond(Integer second) {
|
|
|
|
|
|
if (second == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
int h = second / 3600;
|
|
|
|
|
|
int min = (second % 3600) / 60;
|
|
|
|
|
|
int s = (second % 3600) % 60;
|
2023-08-02 17:59:49 +08:00
|
|
|
|
String rs = "";
|
|
|
|
|
|
if (second >= 3600) {
|
|
|
|
|
|
rs = h + "h";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (second >= 60) {
|
|
|
|
|
|
rs += min + "min";
|
|
|
|
|
|
}
|
|
|
|
|
|
return rs + s + "s";
|
2023-08-01 15:33:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-20 14:26:43 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取天时分秒中文显示,格式:
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param second
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String toDayHourMinSecond(Long second) {
|
|
|
|
|
|
if (second == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
long day = second / 86400;
|
|
|
|
|
|
long h = (second % 86400) / 3600;
|
|
|
|
|
|
long min = (second % 3600) / 60;
|
|
|
|
|
|
long s = (second % 3600) % 60;
|
|
|
|
|
|
String rs = "";
|
|
|
|
|
|
if (second >= 86400) {
|
|
|
|
|
|
rs = day + "天";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (second >= 3600) {
|
|
|
|
|
|
rs += h + "时";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (second >= 60) {
|
|
|
|
|
|
rs += min + "分";
|
|
|
|
|
|
}
|
|
|
|
|
|
return rs + s + "秒";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-01 15:33:17 +08:00
|
|
|
|
public static void main(String[] args) {
|
2024-02-20 14:26:43 +08:00
|
|
|
|
System.out.println(toDayHourMinSecond(1L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(10L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(60L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(360L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(3600L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(13600L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(113600L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(1113600L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(11113600L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(111113600L));
|
|
|
|
|
|
System.out.println(toDayHourMinSecond(1111113600L));
|
2024-01-08 11:18:39 +08:00
|
|
|
|
//abcdefg hijkl mnopq rst uvwxyz
|
2024-02-20 14:26:43 +08:00
|
|
|
|
//for (int i = 0; i < 100; i++) {
|
|
|
|
|
|
// Scanner scanner = new Scanner(System.in);
|
|
|
|
|
|
// char c1 = (char) ('a' + Math.random() * ('z' - 'a' + 1));
|
|
|
|
|
|
// char c2 = (char) ('a' + Math.random() * ('z' - 'a' + 1));
|
|
|
|
|
|
// System.out.println(c1 + ">>>" + c2);
|
|
|
|
|
|
// String read = scanner.nextLine();
|
|
|
|
|
|
// String rs = c1 < c2 ? "y" : "n";
|
|
|
|
|
|
// if (!Objects.equals(read, rs)) {
|
|
|
|
|
|
// System.out.println("答错了");
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2023-08-01 15:33:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|