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 Date
toDate(Instant instant)
Converts anInstant
to ajava.util.Date
.static GregorianCalendar
toGregorianCalendar(ZonedDateTime zdt)
Converts aZonedDateTime
to aCalendar
.static Instant
toInstant(Timestamp sqlTimestamp)
Converts ajava.sql.Timestamp
to anInstant
.static Instant
toInstant(Calendar calendar)
Converts aCalendar
to anInstant
.static Instant
toInstant(Date utilDate)
Converts ajava.util.Date
to anInstant
.static LocalDate
toLocalDate(Date sqlDate)
Converts ajava.sql.Date
to aLocalDate
.static LocalDateTime
toLocalDateTime(Timestamp sqlTimestamp)
Converts ajava.sql.Timestamp
to aLocalDateTime
.static LocalTime
toLocalTime(Time sqlTime)
Converts ajava.sql.Time
to aLocalTime
.static Date
toSqlDate(LocalDate date)
Converts aLocalDate
to ajava.sql.Date
.static Time
toSqlTime(LocalTime time)
Converts aLocalTime
to ajava.sql.Time
.static Timestamp
toSqlTimestamp(Instant instant)
Converts anInstant
to ajava.sql.Timestamp
.static Timestamp
toSqlTimestamp(LocalDateTime dateTime)
Converts aLocalDateTime
to ajava.sql.Timestamp
.static TimeZone
toTimeZone(ZoneId zoneId)
Converts aZoneId
to aTimeZone
.static ZonedDateTime
toZonedDateTime(Calendar calendar)
Converts aCalendar
to aZonedDateTime
.static ZoneId
toZoneId(TimeZone timeZone)
Converts aTimeZone
to aZoneId
.
-
-
-
Method Detail
-
toInstant
public static Instant toInstant(Date utilDate)
Converts ajava.util.Date
to anInstant
.- Parameters:
utilDate
- the util date, not null- Returns:
- the instant, not null
-
toDate
public static Date toDate(Instant instant)
Converts anInstant
to 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 aCalendar
to anInstant
.- Parameters:
calendar
- the calendar, not null- Returns:
- the instant, not null
-
toZonedDateTime
public static ZonedDateTime toZonedDateTime(Calendar calendar)
Converts aCalendar
to aZonedDateTime
.Note that
GregorianCalendar
supports a Julian-Gregorian cutover date andZonedDateTime
does 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 aZonedDateTime
to aCalendar
.The resulting
GregorianCalendar
is 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 aTimeZone
to aZoneId
.- Parameters:
timeZone
- the time-zone, not null- Returns:
- the zone, not null
-
toTimeZone
public static TimeZone toTimeZone(ZoneId zoneId)
Converts aZoneId
to aTimeZone
.- Parameters:
zoneId
- the zone, not null- Returns:
- the time-zone, not null
-
toLocalDate
public static LocalDate toLocalDate(Date sqlDate)
Converts ajava.sql.Date
to aLocalDate
.- Parameters:
sqlDate
- the SQL date, not null- Returns:
- the local date, not null
-
toSqlDate
public static Date toSqlDate(LocalDate date)
Converts aLocalDate
to 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.Time
to aLocalTime
.- Parameters:
sqlTime
- the SQL time, not null- Returns:
- the local time, not null
-
toSqlTime
public static Time toSqlTime(LocalTime time)
Converts aLocalTime
to ajava.sql.Time
.- Parameters:
time
- the local time, not null- Returns:
- the SQL time, not null
-
toSqlTimestamp
public static Timestamp toSqlTimestamp(LocalDateTime dateTime)
Converts aLocalDateTime
to 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.Timestamp
to aLocalDateTime
.- Parameters:
sqlTimestamp
- the SQL timestamp, not null- Returns:
- the local date-time, not null
-
toSqlTimestamp
public static Timestamp toSqlTimestamp(Instant instant)
Converts anInstant
to ajava.sql.Timestamp
.- Parameters:
instant
- the instant, not null- Returns:
- the SQL timestamp, not null
-
-