【时间戳转日时分秒】
程序员文章站
2022-03-01 20:16:51
...
public static String format2Duration(long ms) { long days = MILLISECONDS.toDays(ms); long hours = MILLISECONDS.toDurationHours(ms); long minutes = MILLISECONDS.toDurationMinutes(ms); long seconds = MILLISECONDS.toDurationSeconds(ms); }
static final long C0 = 1L; static final long C1 = C0 * 1000L; static final long C2 = C1 * 1000L; static final long C3 = C2 * 1000L; static final long C4 = C3 * 60L; static final long C5 = C4 * 60L; static final long C6 = C5 * 24L; /** * Time unit representing one thousandth of a second */ public static class MILLISECONDS { public static long toSeconds(long d) { return d / (C3 / C2); } public static long toMinutes(long d) { return d / (C4 / C2); } public static long toHours(long d) { return d / (C5 / C2); } public static long toDays(long d) { return d / (C6 / C2); } public static long toDurationSeconds(long d) { return (d % (C4 / C2)) / (C3 / C2); } public static long toDurationMinutes(long d) { return (d % (C5 / C2)) / (C4 / C2); } public static long toDurationHours(long d) { return (d % (C6 / C2)) / (C5 / C2); } }
代码来自dolphinscheduler中DateUtils部分