public final class DateTimeUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static Calendar |
addDaysToCalendar(Calendar calendar,
int days)
Adds the specified amount of days to the given calendar field.
|
static Date |
addDaysToDate(Date date,
int days)
Adds the specified amount of days to the given date.
|
static Date |
addMillisToDate(Date date,
long millis)
Adds provided number of milliseconds to the Date.
|
static Date |
addYearsToDate(Date date,
int years)
Adds the specified amount of years to the given date.
|
static Date |
createUtcDateTime(int year,
int month,
int day,
int hour,
int minute,
int second)
Creates UTC Date based on provided parameters.
|
static String |
dateToString(Calendar date)
Converts
Calendar date to string of "yyyy.MM.dd HH:mm:ss z" format. |
static String |
format(Date date,
String pattern)
Format passing date with specified pattern.
|
static String |
formatWithDefaultPattern(Date date)
Format passing date with default yyyy-MM-dd pattern.
|
static Calendar |
getCalendar(Date date)
Gets the date as
Calendar. |
static Calendar |
getCurrentTimeCalendar()
Gets a default
GregorianCalendar. |
static Date |
getCurrentTimeDate()
Gets current time consistently.
|
static long |
getCurrentTimeZoneOffset(Date date)
Gets the offset of time zone from UTC at the specified date.
|
static LocalDateTime |
getLocalDateTime()
Gets local current time consistently.
|
static long |
getRelativeTime(Date date)
Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT
represented by specified date.
|
static LocalDateTime |
getTimeFromMillis(long milliseconds)
Gets the
LocalDateTime from milliseconds. |
static double |
getUtcMillisFromEpoch(Calendar calendar)
Gets the
Calendar as UTC milliseconds from the epoch. |
static boolean |
isInPast(Date date)
Defines if date is in past.
|
static LocalDateTime |
ofEpochSecondUTC(long epochSecond)
Gets the
LocalDateTime from UTC seconds from the epoch. |
static Date |
parse(String date,
String format)
Parses passing date with specified format.
|
static String |
parseLocalDateTime(LocalDateTime dateTime,
String format)
Parses
LocalDateTime local date time according to specified format. |
static LocalDateTime |
parseToLocalDateTime(String date,
String format)
Parses date with specified format into
LocalDateTime. |
static Date |
parseWithDefaultPattern(String date)
Parses passing date with default yyyy-MM-dd pattern.
|
static String |
serializeDateToISO8601(LocalDateTime dateTime)
Serialize time using format YYYY-MM-DDTHH-MM-SS
|
public static double getUtcMillisFromEpoch(Calendar calendar)
Calendar as UTC milliseconds from the epoch.calendar - the calendar to be converted to millispublic static LocalDateTime ofEpochSecondUTC(long epochSecond)
LocalDateTime from UTC seconds from the epoch.epochSecond - the UTC milliseconds from the epochpublic static Calendar getCurrentTimeCalendar()
GregorianCalendar.GregorianCalendar using the current time in the default
time zone with the default localepublic static Date getCurrentTimeDate()
public static LocalDateTime getLocalDateTime()
LocalDateTime at which it was allocated, measured to the nearest millisecondpublic static Calendar addDaysToCalendar(Calendar calendar, int days)
calendar - the calendar field where to adddays - the amount of days to be addedpublic static boolean isInPast(Date date)
date - the date to be compared with current datetrue if given date is in past, false insteadpublic static long getRelativeTime(Date date)
date - the specified date to get timepublic static Date addMillisToDate(Date date, long millis)
public static Date addDaysToDate(Date date, int days)
date - the specified date to adddays - the amount of days to be addedDate object representing the calendar's time value (millisecond
offset from the Epoch)public static Date addYearsToDate(Date date, int years)
date - the specified date to addyears - the amount of years to be addedDate object representing the calendar's time value (millisecond
offset from the Epoch)public static Date parseWithDefaultPattern(String date)
date - is date to be parsepublic static Date parse(String date, String format)
date - the date to be parsedformat - the format of parsing the datepublic static LocalDateTime parseToLocalDateTime(String date, String format)
LocalDateTime.date - String date to parseformat - String parsing formatLocalDateTime parsed datepublic static String parseLocalDateTime(LocalDateTime dateTime, String format)
LocalDateTime local date time according to specified format.dateTime - LocalDateTime to parseformat - String parsing formatStringpublic static String formatWithDefaultPattern(Date date)
date - the date to be formattedpublic static String format(Date date, String pattern)
date - date to be formattedpattern - pattern for formatpublic static long getCurrentTimeZoneOffset(Date date)
date - the date represented in milliseconds since January 1, 1970 00:00:00 GMTpublic static String dateToString(Calendar date)
Calendar date to string of "yyyy.MM.dd HH:mm:ss z" format.date - to convert.public static LocalDateTime getTimeFromMillis(long milliseconds)
LocalDateTime from milliseconds.milliseconds - the UTC milliseconds from the epochLocalDateTime converted from millisecondspublic static Date createUtcDateTime(int year, int month, int day, int hour, int minute, int second)
year - as int to be createdmonth - as int to be createdday - as int to be createdhour - as int to be createdminute - as int to be createdsecond - as int to be createdpublic static String serializeDateToISO8601(LocalDateTime dateTime)
dateTime - local time to be convertedCopyright © 1998–2026 Apryse Group NV. All rights reserved.