Package org.threeten.bp
Class DateTimeUtils
- java.lang.Object
-
- org.threeten.bp.DateTimeUtils
-
public final class DateTimeUtils extends Object
A set of utilities to assist in bridging the gap to Java 8.This class is not found in Java SE 8 but provides methods that are.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DatetoDate(Instant instant)Converts anInstantto ajava.util.Date.static GregorianCalendartoGregorianCalendar(ZonedDateTime zdt)Converts aZonedDateTimeto aCalendar.static InstanttoInstant(Timestamp sqlTimestamp)Converts ajava.sql.Timestampto anInstant.static InstanttoInstant(Calendar calendar)Converts aCalendarto anInstant.static InstanttoInstant(Date utilDate)Converts ajava.util.Dateto anInstant.static LocalDatetoLocalDate(Date sqlDate)Converts ajava.sql.Dateto aLocalDate.static LocalDateTimetoLocalDateTime(Timestamp sqlTimestamp)Converts ajava.sql.Timestampto aLocalDateTime.static LocalTimetoLocalTime(Time sqlTime)Converts ajava.sql.Timeto aLocalTime.static DatetoSqlDate(LocalDate date)Converts aLocalDateto ajava.sql.Date.static TimetoSqlTime(LocalTime time)Converts aLocalTimeto ajava.sql.Time.static TimestamptoSqlTimestamp(Instant instant)Converts anInstantto ajava.sql.Timestamp.static TimestamptoSqlTimestamp(LocalDateTime dateTime)Converts aLocalDateTimeto ajava.sql.Timestamp.static TimeZonetoTimeZone(ZoneId zoneId)Converts aZoneIdto aTimeZone.static ZonedDateTimetoZonedDateTime(Calendar calendar)Converts aCalendarto aZonedDateTime.static ZoneIdtoZoneId(TimeZone timeZone)Converts aTimeZoneto aZoneId.
-
-
-
Method Detail
-
toInstant
public static Instant toInstant(Date utilDate)
Converts ajava.util.Dateto anInstant.- Parameters:
utilDate- the util date, not null- Returns:
- the instant, not null
-
toDate
public static Date toDate(Instant instant)
Converts anInstantto ajava.util.Date.Fractions of the instant smaller than milliseconds will be dropped.
- Parameters:
instant- the instant, not null- Returns:
- the util date, not null
- Throws:
IllegalArgumentException- if the conversion fails
-
toInstant
public static Instant toInstant(Calendar calendar)
Converts aCalendarto anInstant.- Parameters:
calendar- the calendar, not null- Returns:
- the instant, not null
-
toZonedDateTime
public static ZonedDateTime toZonedDateTime(Calendar calendar)
Converts aCalendarto aZonedDateTime.Note that
GregorianCalendarsupports a Julian-Gregorian cutover date andZonedDateTimedoes not so some differences will occur.- Parameters:
calendar- the calendar, not null- Returns:
- the instant, not null
-
toGregorianCalendar
public static GregorianCalendar toGregorianCalendar(ZonedDateTime zdt)
Converts aZonedDateTimeto aCalendar.The resulting
GregorianCalendaris pure Gregorian and uses ISO week definitions, starting on Monday and with 4 days in a minimal week.Fractions of the instant smaller than milliseconds will be dropped.
- Parameters:
zdt- the zoned date-time, not null- Returns:
- the calendar, not null
- Throws:
IllegalArgumentException- if the conversion fails
-
toZoneId
public static ZoneId toZoneId(TimeZone timeZone)
Converts aTimeZoneto aZoneId.- Parameters:
timeZone- the time-zone, not null- Returns:
- the zone, not null
-
toTimeZone
public static TimeZone toTimeZone(ZoneId zoneId)
Converts aZoneIdto aTimeZone.- Parameters:
zoneId- the zone, not null- Returns:
- the time-zone, not null
-
toLocalDate
public static LocalDate toLocalDate(Date sqlDate)
Converts ajava.sql.Dateto aLocalDate.- Parameters:
sqlDate- the SQL date, not null- Returns:
- the local date, not null
-
toSqlDate
public static Date toSqlDate(LocalDate date)
Converts aLocalDateto ajava.sql.Date.- Parameters:
date- the local date, not null- Returns:
- the SQL date, not null
-
toLocalTime
public static LocalTime toLocalTime(Time sqlTime)
Converts ajava.sql.Timeto aLocalTime.- Parameters:
sqlTime- the SQL time, not null- Returns:
- the local time, not null
-
toSqlTime
public static Time toSqlTime(LocalTime time)
Converts aLocalTimeto ajava.sql.Time.- Parameters:
time- the local time, not null- Returns:
- the SQL time, not null
-
toSqlTimestamp
public static Timestamp toSqlTimestamp(LocalDateTime dateTime)
Converts aLocalDateTimeto ajava.sql.Timestamp.- Parameters:
dateTime- the local date-time, not null- Returns:
- the SQL timestamp, not null
-
toLocalDateTime
public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp)
Converts ajava.sql.Timestampto aLocalDateTime.- Parameters:
sqlTimestamp- the SQL timestamp, not null- Returns:
- the local date-time, not null
-
toSqlTimestamp
public static Timestamp toSqlTimestamp(Instant instant)
Converts anInstantto ajava.sql.Timestamp.- Parameters:
instant- the instant, not null- Returns:
- the SQL timestamp, not null
-
-