From 4e7fc4216787fe7b6043a87ed164c9f7c9641b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Tue, 10 Apr 2018 22:34:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taboolib/timeutil/TimeFormatter.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/me/skymc/taboolib/timeutil/TimeFormatter.java diff --git a/src/main/java/me/skymc/taboolib/timeutil/TimeFormatter.java b/src/main/java/me/skymc/taboolib/timeutil/TimeFormatter.java new file mode 100644 index 0000000..b3fdb4a --- /dev/null +++ b/src/main/java/me/skymc/taboolib/timeutil/TimeFormatter.java @@ -0,0 +1,31 @@ +package me.skymc.taboolib.timeutil; + +import java.util.concurrent.TimeUnit; + +import lombok.Data; + +/** + * @author sky + * @since 2018-04-10 22:11:04 + */ +@Data +public class TimeFormatter { + + private long days; + private long hours; + private long minutes; + private long seconds; + private long milliseconds; + + public TimeFormatter(long millisecond) { + days = TimeUnit.MILLISECONDS.toDays(millisecond); + hours = TimeUnit.MILLISECONDS.toHours(millisecond) - days * 24L; + minutes = TimeUnit.MILLISECONDS.toMinutes(millisecond) - TimeUnit.MILLISECONDS.toHours(millisecond) * 60L; + seconds = TimeUnit.MILLISECONDS.toSeconds(millisecond) - TimeUnit.MILLISECONDS.toMinutes(millisecond) * 60L; + milliseconds = TimeUnit.MILLISECONDS.toMillis(millisecond) - TimeUnit.MILLISECONDS.toSeconds(millisecond) * 1000L; + } + + public long toMilliseconds() { + return milliseconds + (seconds * 1000L) + (minutes * 1000L * 60L) + (hours * 1000L * 60L * 60L) + (days * 1000L * 60L * 60L * 24L); + } +}