Package org.kiwiproject.time
Class KiwiDateTimeConverters
- java.lang.Object
-
- org.kiwiproject.time.KiwiDateTimeConverters
-
public class KiwiDateTimeConverters extends Object
A collection of small utility methods to convert between legacyDateand the Java 8 date/time API classes.Mainly, these utilities save you some typing and having to remember the chains of method calls you need to make when doing these conversions.
All methods throw
IllegalArgumentExceptionif null values are passed into them.
-
-
Constructor Summary
Constructors Constructor Description KiwiDateTimeConverters()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DatetoDate(LocalDate localDate)static DatetoDate(LocalDateTime localDateTime)Convert the givenLocalDateTimeinto its equivalentDate(epoch milliseconds using UTC).static DatetoDate(ZonedDateTime zonedDateTime)Convert the givenZonedDateTimeinto its equivalentDate(epoch milliseconds using UTC).static LocalDatetoLocalDate(Date date, ZoneId zoneId)static LocalDateTimetoLocalDateTime(Date date, ZoneId zoneId)Convert the givenDateinto its equivalentLocalDateTimein the specified time zone.static LocalDateTimetoLocalDateTimeUTC(Date date)Convert the givenDateinto its equivalentLocalDateTimein the UTC time zone.static LocalDatetoLocalDateUTC(Date date)static ZonedDateTimetoZonedDateTime(Date date, ZoneId zoneId)Convert the givenDateinto its equivalentZonedDateTimein the specified time zone.static ZonedDateTimetoZonedDateTimeUTC(Date date)Convert the givenDateinto its equivalentZonedDateTimein the UTC time zone.
-
-
-
Method Detail
-
toDate
public static Date toDate(LocalDateTime localDateTime)
Convert the givenLocalDateTimeinto its equivalentDate(epoch milliseconds using UTC).- Parameters:
localDateTime- theLocalDateTimeto convert- Returns:
- the converted
Date
-
toDate
public static Date toDate(ZonedDateTime zonedDateTime)
Convert the givenZonedDateTimeinto its equivalentDate(epoch milliseconds using UTC).- Parameters:
zonedDateTime- theZonedDateTimeto convert- Returns:
- the converted
Date
-
toLocalDateTimeUTC
public static LocalDateTime toLocalDateTimeUTC(Date date)
Convert the givenDateinto its equivalentLocalDateTimein the UTC time zone.- Parameters:
date- theDateto convert- Returns:
- the converted
LocalDateTime - See Also:
ZoneOffset.UTC
-
toLocalDateTime
public static LocalDateTime toLocalDateTime(Date date, ZoneId zoneId)
Convert the givenDateinto its equivalentLocalDateTimein the specified time zone.- Parameters:
date- theDateto convertzoneId- the time zone as aZoneId- Returns:
- the converted
LocalDateTime
-
toZonedDateTimeUTC
public static ZonedDateTime toZonedDateTimeUTC(Date date)
Convert the givenDateinto its equivalentZonedDateTimein the UTC time zone.- Parameters:
date- theDateto convert- Returns:
- the converted
ZonedDateTime - See Also:
ZoneOffset.UTC
-
toZonedDateTime
public static ZonedDateTime toZonedDateTime(Date date, ZoneId zoneId)
Convert the givenDateinto its equivalentZonedDateTimein the specified time zone.- Parameters:
date- theDateto convertzoneId- the time zone as aZoneId- Returns:
- the converted
ZonedDateTime
-
-