public final class TimeUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static long |
msInDay |
static long |
msInHour |
static long |
msInMinute |
static long |
msInSecond |
static long |
msInWeek
Constants for time calculations.
|
static long |
nsInMillisecond |
static long |
nsInSecond |
| Modifier and Type | Method and Description |
|---|---|
static void |
changeByDays(Calendar calendar,
int days)
Changes calendar date by the specified days amount.
|
static Date |
currentDate()
Returns current system date.
|
static long |
currentNanoTime()
Returns current system nano time.
|
static long |
currentTime()
Returns current system time.
|
static void |
decreaseByDay(Calendar calendar)
Decreases calendar date by one day.
|
static String |
formatCurrentDate(String format)
Returns formatted representation of current date.
|
static String |
formatDate(String format,
Date date)
Returns formatted representation of specified date.
|
static Date |
getEndOfDay(Date date)
Returns end-of-day date.
|
static Long |
getLastNanoTime()
Returns either last pinned nanotime or last request nanotime.
|
static Long |
getLastTime()
Returns either last pinned time or last request time.
|
static long |
getPassedNanoTime()
Returns nanotime passed since either last pin request or last nanotime request.
|
static long |
getPassedNanoTime(boolean total)
Returns nanotime passed since either last pin request or last nanotime request if total is false.
|
static long |
getPassedTime()
Returns time passed since either last pin request or last time request.
|
static long |
getPassedTime(boolean total)
Returns time passed since either last pin request or last time request if total is false.
|
static Long |
getPinnedNanoTime()
Returns last pinned nanotime.
|
static Long |
getPinnedTime()
Returns last pinned time.
|
static Date |
getStartOfDay(Date date)
Returns start-of-day date.
|
static void |
increaseByDay(Calendar calendar)
Increases calendar date by one day.
|
static boolean |
isSameDay(Calendar calendar,
Date date)
Returns true if date contained in Calendar and specified date both represent the same day.
|
static boolean |
isSameDay(Calendar calendar,
Long date)
Returns true if date contained in Calendar and specified time both represent the same day.
|
static boolean |
isSameDay(Date date1,
Date date2)
Returns true if both of the dates represent the same day.
|
static boolean |
isSameDay(Long time1,
Long time2)
Returns true if both of the time represent the same day.
|
static void |
pinNanoTime()
Pins current system nanotime.
|
static void |
pinTime()
Pins current system time.
|
static void |
resetNanoTime()
Resets last pinned nanotime and last request nanotime.
|
static void |
resetTime()
Resets last pinned time and last request time.
|
static void |
showPassedNanoTime()
Writes nanotime passed since either last pin request or last nanotime request to log.
|
static void |
showPassedNanoTime(boolean total)
Writes nanotime passed since either last pin request or last nanotime request if total is false to log.
|
static void |
showPassedNanoTime(boolean total,
String prefix)
Writes nanotime passed since either last pin request or last nanotime request if total is false to log with specified prefix.
|
static void |
showPassedNanoTime(String prefix)
Writes nanotime passed since either last pin request or last nanotime request to log with specified prefix.
|
static void |
showPassedTime()
Writes time passed since either last pin request or last time request to log.
|
static void |
showPassedTime(boolean total)
Writes time passed since either last pin request or last time request if total is false to log.
|
static void |
showPassedTime(boolean total,
String prefix)
Writes time passed since either last pin request or last time request if total is false to log with specified prefix.
|
static void |
showPassedTime(String prefix)
Writes time passed since either last pin request or last time request to log with specified prefix.
|
public static final long msInWeek
public static final long msInDay
public static final long msInHour
public static final long msInMinute
public static final long msInSecond
public static final long nsInSecond
public static final long nsInMillisecond
@Nullable public static Long getPinnedTime()
@Nullable public static Long getLastTime()
public static void pinTime()
public static long getPassedTime()
public static long getPassedTime(boolean total)
total - should always return time passed since last pin request or notpublic static void showPassedTime()
public static void showPassedTime(@NotNull String prefix)
prefix - output string prefixpublic static void showPassedTime(boolean total)
total - should always write time passed since last pin request or notpublic static void showPassedTime(boolean total,
@NotNull
String prefix)
total - should always write time passed since last pin request or notprefix - output string prefixpublic static void resetTime()
@Nullable public static Long getPinnedNanoTime()
@Nullable public static Long getLastNanoTime()
public static void pinNanoTime()
public static long getPassedNanoTime()
public static long getPassedNanoTime(boolean total)
total - should always return time passed since last pin request or notpublic static void showPassedNanoTime()
public static void showPassedNanoTime(@NotNull String prefix)
prefix - output string prefixpublic static void showPassedNanoTime(boolean total)
total - should always write nanotime passed since last pin request or notpublic static void showPassedNanoTime(boolean total,
@NotNull
String prefix)
total - should always write nanotime passed since last pin request or notprefix - output string prefixpublic static void resetNanoTime()
public static long currentTime()
public static long currentNanoTime()
@NotNull public static Date currentDate()
public static boolean isSameDay(@NotNull Date date1, @NotNull Date date2)
date1 - first datedate2 - second datepublic static boolean isSameDay(@NotNull Long time1, @NotNull Long time2)
time1 - first timetime2 - second timepublic static boolean isSameDay(@NotNull Calendar calendar, @NotNull Date date)
calendar - calendardate - datepublic static boolean isSameDay(@NotNull Calendar calendar, @NotNull Long date)
calendar - calendardate - date@NotNull public static Date getStartOfDay(@NotNull Date date)
date - date to process@NotNull public static Date getEndOfDay(@NotNull Date date)
date - date to processpublic static void increaseByDay(@NotNull Calendar calendar)
calendar - calendar that should be changedpublic static void decreaseByDay(@NotNull Calendar calendar)
calendar - calendar that should be changedpublic static void changeByDays(@NotNull Calendar calendar, int days)
calendar - calendar that should be changeddays - days amount@NotNull public static String formatCurrentDate(@NotNull String format)
format - date format to useCopyright © 2020. All rights reserved.