Package com.arakelian.core.utils
Class DateUtils
- java.lang.Object
-
- com.arakelian.core.utils.DateUtils
-
public class DateUtils extends java.lang.ObjectGeneric date parsing and conversion utilities Note: Consider at some point removing dependency on joda-time and switching to Java 8 time.- See Also:
- http://time4j.net/tutorial/appendix.html
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDateUtils.EpochUnits
-
Field Summary
Fields Modifier and Type Field Description static java.time.format.DateTimeFormatterEEE_M_D_YYThread-safe Sat M/D/YY formatterstatic java.time.format.DateTimeFormatterH_MM_ampmThread-safe HH:MM am/pmstatic java.time.format.DateTimeFormatterM_D_YYThread-safe M/D/YY formatterstatic java.time.format.DateTimeFormatterMMDDYYYY_HHMMThread-safe Date with time (without seconds)static java.time.format.DateTimeFormatterMMDDYYYY_HHMMSSThread-safe Date with time (including seconds)static java.time.ZoneIdUTC_ZONEstatic java.time.format.DateTimeFormatterYYYY_MMThread-safe YYYY/MM/DD formatterstatic java.time.format.DateTimeFormatterYYYY_MM_DDThread-safe YYYY/MM/DD formatter
-
Constructor Summary
Constructors Constructor Description DateUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.time.ZonedDateTimeatStartOfDay(java.time.ZonedDateTime date)static intcompare(java.util.Date d1, java.util.Date d2)static java.time.format.DateTimeFormatterdayMonthYear(java.time.format.TextStyle monthStyle, java.lang.String daySeparator, java.lang.String monthSeparator, int yearDigits)static booleanhasSameDate(java.time.ZonedDateTime lhs, java.time.ZonedDateTime rhs)static booleanhasTimeComponent(java.time.ZonedDateTime dateTime)static booleanhasTimeComponent(java.util.Date date)static booleanisUtc(java.time.ZonedDateTime date)static java.time.format.DateTimeFormattermonthDayYear(java.time.format.TextStyle monthStyle, java.lang.String monthSeparator, java.lang.String daySeparator, int yearDigits, boolean time)static java.time.ZonedDateTimenowWithZoneUtc()static <T> Tparse(java.lang.String text, java.time.ZoneId zoneIfNotSpecified, java.time.temporal.TemporalQuery<T> query)static <T> TparseChecked(java.lang.String text, java.time.ZoneId zoneIfNotSpecified, java.time.temporal.TemporalQuery<T> query)static java.time.ZonedDateTimerandomZonedDateTimeUtc(java.time.ZonedDateTime from, java.time.ZonedDateTime to)static java.time.ZonedDateTimerandomZonedDateTimeUtc(java.util.Random random, java.time.ZonedDateTime from, java.time.ZonedDateTime to)static longtimeBetween(java.time.ZonedDateTime firstDate, java.time.ZonedDateTime secondDate, java.time.temporal.ChronoUnit units)static java.util.DatetoDate(java.time.Instant instant)static java.util.DatetoDate(java.time.LocalDateTime date)static java.util.DatetoDate(java.time.LocalDateTime date, java.time.ZoneOffset offset)static java.util.DatetoDate(java.time.ZonedDateTime date)static longtoEpochMillisUtc(java.time.ZonedDateTime date)static java.time.LocalDateTimetoLocalDateTime(java.lang.String text)static java.time.LocalDateTimetoLocalDateTimeChecked(java.lang.String text)static longtoNanos(int millis)static java.lang.StringtoStringIsoFormat(java.lang.String date)static java.lang.StringtoStringIsoFormat(java.time.ZonedDateTime date)Returns the givenZonedDateTimein ISO format that readable by a wide range of clients.static java.time.ZonedDateTimetoUtc(java.time.ZonedDateTime date)static java.time.ZonedDateTimetoZonedDateTimeUtc(int year, java.time.Month month, int dayOfMonth)static java.time.ZonedDateTimetoZonedDateTimeUtc(long epoch)Returns aZonedDateTimefrom the given epoch value.static java.time.ZonedDateTimetoZonedDateTimeUtc(long epochValue, DateUtils.EpochUnits units)Returns aZonedDateTimefrom the given epoch value.static java.time.ZonedDateTimetoZonedDateTimeUtc(java.lang.String text)static java.time.ZonedDateTimetoZonedDateTimeUtc(java.time.Instant instant)static java.time.ZonedDateTimetoZonedDateTimeUtc(java.time.LocalDate date)static java.time.ZonedDateTimetoZonedDateTimeUtc(java.util.Date date)static java.time.ZonedDateTimetoZonedDateTimeUtcChecked(java.lang.String text)static java.time.ZonedDateTimewithDatePrecision(java.time.ZonedDateTime date)static java.time.format.DateTimeFormatteryearMonthDay(java.time.format.TextStyle monthStyle, java.lang.String yearSeparator, java.lang.String monthSeparator, int yearDigits, boolean time)
-
-
-
Field Detail
-
MMDDYYYY_HHMM
public static final java.time.format.DateTimeFormatter MMDDYYYY_HHMM
Thread-safe Date with time (without seconds)
-
MMDDYYYY_HHMMSS
public static final java.time.format.DateTimeFormatter MMDDYYYY_HHMMSS
Thread-safe Date with time (including seconds)
-
YYYY_MM
public static final java.time.format.DateTimeFormatter YYYY_MM
Thread-safe YYYY/MM/DD formatter
-
YYYY_MM_DD
public static final java.time.format.DateTimeFormatter YYYY_MM_DD
Thread-safe YYYY/MM/DD formatter
-
M_D_YY
public static final java.time.format.DateTimeFormatter M_D_YY
Thread-safe M/D/YY formatter
-
EEE_M_D_YY
public static final java.time.format.DateTimeFormatter EEE_M_D_YY
Thread-safe Sat M/D/YY formatter
-
H_MM_ampm
public static final java.time.format.DateTimeFormatter H_MM_ampm
Thread-safe HH:MM am/pm
-
UTC_ZONE
public static final java.time.ZoneId UTC_ZONE
-
-
Method Detail
-
atStartOfDay
public static java.time.ZonedDateTime atStartOfDay(java.time.ZonedDateTime date)
-
compare
public static int compare(java.util.Date d1, java.util.Date d2)
-
dayMonthYear
public static java.time.format.DateTimeFormatter dayMonthYear(java.time.format.TextStyle monthStyle, java.lang.String daySeparator, java.lang.String monthSeparator, int yearDigits)
-
hasSameDate
public static boolean hasSameDate(java.time.ZonedDateTime lhs, java.time.ZonedDateTime rhs)
-
hasTimeComponent
public static boolean hasTimeComponent(java.util.Date date)
-
hasTimeComponent
public static boolean hasTimeComponent(java.time.ZonedDateTime dateTime)
-
isUtc
public static boolean isUtc(java.time.ZonedDateTime date)
-
monthDayYear
public static java.time.format.DateTimeFormatter monthDayYear(java.time.format.TextStyle monthStyle, java.lang.String monthSeparator, java.lang.String daySeparator, int yearDigits, boolean time)
-
nowWithZoneUtc
public static java.time.ZonedDateTime nowWithZoneUtc()
-
parse
public static <T> T parse(java.lang.String text, java.time.ZoneId zoneIfNotSpecified, java.time.temporal.TemporalQuery<T> query)
-
parseChecked
public static <T> T parseChecked(java.lang.String text, java.time.ZoneId zoneIfNotSpecified, java.time.temporal.TemporalQuery<T> query) throws java.time.format.DateTimeParseException- Throws:
java.time.format.DateTimeParseException
-
randomZonedDateTimeUtc
public static java.time.ZonedDateTime randomZonedDateTimeUtc(java.util.Random random, java.time.ZonedDateTime from, java.time.ZonedDateTime to)
-
randomZonedDateTimeUtc
public static java.time.ZonedDateTime randomZonedDateTimeUtc(java.time.ZonedDateTime from, java.time.ZonedDateTime to)
-
timeBetween
public static long timeBetween(java.time.ZonedDateTime firstDate, java.time.ZonedDateTime secondDate, java.time.temporal.ChronoUnit units)
-
toDate
public static java.util.Date toDate(java.time.Instant instant)
-
toDate
public static java.util.Date toDate(java.time.LocalDateTime date)
-
toDate
public static java.util.Date toDate(java.time.LocalDateTime date, java.time.ZoneOffset offset)
-
toDate
public static java.util.Date toDate(java.time.ZonedDateTime date)
-
toEpochMillisUtc
public static long toEpochMillisUtc(java.time.ZonedDateTime date)
-
toLocalDateTime
public static java.time.LocalDateTime toLocalDateTime(java.lang.String text)
-
toLocalDateTimeChecked
public static java.time.LocalDateTime toLocalDateTimeChecked(java.lang.String text) throws java.time.format.DateTimeParseException- Throws:
java.time.format.DateTimeParseException
-
toNanos
public static long toNanos(int millis)
-
toStringIsoFormat
public static java.lang.String toStringIsoFormat(java.lang.String date)
-
toStringIsoFormat
public static java.lang.String toStringIsoFormat(java.time.ZonedDateTime date)
Returns the given
ZonedDateTimein ISO format that readable by a wide range of clients.In general the format has these components:
- A date:
yyyy '-' MM '-' dd - A time:
'T' HH ':' mm ':' ss - Milliseconds:
('.' | ',') digit+ - UTC offset:
'Z'
- Parameters:
date- a zoned date/time value- Returns:
- the given
ZonedDateTimein ISO format - See Also:
- dateOptionalTimeParser, strict_date_optional_time
- A date:
-
toUtc
public static java.time.ZonedDateTime toUtc(java.time.ZonedDateTime date)
-
toZonedDateTimeUtc
public static java.time.ZonedDateTime toZonedDateTimeUtc(java.util.Date date)
-
toZonedDateTimeUtc
public static java.time.ZonedDateTime toZonedDateTimeUtc(java.time.Instant instant)
-
toZonedDateTimeUtc
public static java.time.ZonedDateTime toZonedDateTimeUtc(int year, java.time.Month month, int dayOfMonth)
-
toZonedDateTimeUtc
public static java.time.ZonedDateTime toZonedDateTimeUtc(java.time.LocalDate date)
-
toZonedDateTimeUtc
public static java.time.ZonedDateTime toZonedDateTimeUtc(long epoch)
Returns aZonedDateTimefrom the given epoch value. Note that this implementation attempts to protect against caller providing timestamps in different units. For example, Unix timestamps are the number of SECONDS since January 1, 1970, while Java Dates are number of MILLISECONDS since January 1, 1970.- Parameters:
epoch- timestamp value in seconds, milliseconds or microseconds- Returns:
- a
ZonedDateTimeor null if the date is not valid
-
toZonedDateTimeUtc
public static java.time.ZonedDateTime toZonedDateTimeUtc(long epochValue, DateUtils.EpochUnits units)Returns aZonedDateTimefrom the given epoch value.- Parameters:
epochValue- value in millisecondsunits- epoch units- Returns:
- a
ZonedDateTimeor null if the date is not valid
-
toZonedDateTimeUtc
public static java.time.ZonedDateTime toZonedDateTimeUtc(java.lang.String text)
-
toZonedDateTimeUtcChecked
public static java.time.ZonedDateTime toZonedDateTimeUtcChecked(java.lang.String text) throws java.time.format.DateTimeParseException- Throws:
java.time.format.DateTimeParseException
-
withDatePrecision
public static java.time.ZonedDateTime withDatePrecision(java.time.ZonedDateTime date)
-
yearMonthDay
public static java.time.format.DateTimeFormatter yearMonthDay(java.time.format.TextStyle monthStyle, java.lang.String yearSeparator, java.lang.String monthSeparator, int yearDigits, boolean time)
-
-