Package org.kingdoms.utils.time
Class TimeUtils
java.lang.Object
org.kingdoms.utils.time.TimeUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateTimeFormatterstatic final DateTimeFormatterstatic final DateTimeFormatterstatic ZoneId -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longstatic ZonedDateTimeepoch()static StringBuilderformatTime(DateTimeFormatter formatter, TemporalAccessor accessor, int buffer) static StringBuildergetDate()static StringBuildergetDate(long epoch) static StringBuildergetDate(TemporalAccessor accessor) static StringBuilderstatic StringBuildergetDateAndTime(long epoch) static StringBuildergetDateAndTime(TemporalAccessor accessor) Gets the current full time.static StringBuildergetTime()Gets the current time.static StringBuildergetTime(long epoch) static StringBuildergetTime(TemporalAccessor accessor) static longgetTimeUntil(CharSequence time, String timeZone, ChronoUnit timeUnit) Gets the time difference between the current time and the specified time using the argument time unit.static DurationgetTimeUntilTomrrow(ZoneId timezone) static longmillisToTicks(long millis) A gametick is where Minecraft's game loop runs once.static ZonedDateTimenow()static Longstatic LongCalculate a time in a form of a string.static longstatic voidvalidateUnixTime(long time)
-
Field Details
-
TIME_UNITS
-
TIME_ZONE
-
DATE_TIME_FORMAT
-
DATE_FORMAT
-
TIME_FORMAT
-
-
Constructor Details
-
TimeUtils
public TimeUtils()
-
-
Method Details
-
validateUnixTime
public static void validateUnixTime(long time) -
getDateAndTime
Gets the current full time.- Returns:
- current time with the format of yyyy/MM/dd hh:mm:ss
- Since:
- 1.0.0
-
formatTime
@Nonnull public static StringBuilder formatTime(DateTimeFormatter formatter, TemporalAccessor accessor, int buffer) -
getDateAndTime
-
now
-
epoch
-
getDateAndTime
-
getTime
Gets the current time.- Returns:
- current time with the format of hh:mm:ss
- Since:
- 1.0.0
-
getTime
-
getTime
-
afterNow
-
getDate
-
getDate
-
getDate
-
getTimeUntil
Gets the time difference between the current time and the specified time using the argument time unit.- Parameters:
time- the local time to parse.timeZone- the time zone from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones- Returns:
- ticks until the specified time.
-
getTimeUntilTomrrow
-
parseTime
-
parseTime
Calculate a time in a form of a string. Supports days to milliseconds.
Acts exactly like the RegEx expression(\d+)(\S*)- Parameters:
time- the string time with its unit.- Returns:
- the parsed milliseconds from the time unit.
-
millisToTicks
public static long millisToTicks(long millis) A gametick is where Minecraft's game loop runs once. The game normally runs at a fixed rate of 20 ticks per second, so one tick happens every 0.05 seconds (50 milliseconds, or five hundredths of a second), making an in-game day lasts exactly 24000 ticks, or 20 minutes.- Parameters:
millis- the milliseconds.- Returns:
- game ticks with -1 ticks error.
-
toTicks
-