Package org.threeten.bp
Class DateTimeUtils
java.lang.Object
org.threeten.bp.DateTimeUtils
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DateConverts anInstantto ajava.util.Date.static GregorianCalendarConverts aZonedDateTimeto aCalendar.static InstantConverts ajava.sql.Timestampto anInstant.static InstantConverts aCalendarto anInstant.static InstantConverts 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 DateConverts aLocalDateto ajava.sql.Date.static TimeConverts 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 ZoneIdConverts aTimeZoneto aZoneId.
-
Constructor Details
-
DateTimeUtils
private DateTimeUtils()Restricted constructor.
-
-
Method Details
-
toInstant
Converts ajava.util.Dateto anInstant.- Parameters:
utilDate- the util date, not null- Returns:
- the instant, not null
-
toDate
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
Converts aCalendarto anInstant.- Parameters:
calendar- the calendar, not null- Returns:
- the instant, not null
-
toZonedDateTime
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
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
Converts aTimeZoneto aZoneId.- Parameters:
timeZone- the time-zone, not null- Returns:
- the zone, not null
-
toTimeZone
Converts aZoneIdto aTimeZone.- Parameters:
zoneId- the zone, not null- Returns:
- the time-zone, not null
-
toLocalDate
Converts ajava.sql.Dateto aLocalDate.- Parameters:
sqlDate- the SQL date, not null- Returns:
- the local date, not null
-
toSqlDate
Converts aLocalDateto ajava.sql.Date.- Parameters:
date- the local date, not null- Returns:
- the SQL date, not null
-
toLocalTime
Converts ajava.sql.Timeto aLocalTime.- Parameters:
sqlTime- the SQL time, not null- Returns:
- the local time, not null
-
toSqlTime
Converts aLocalTimeto ajava.sql.Time.- Parameters:
time- the local time, not null- Returns:
- the SQL time, not null
-
toSqlTimestamp
Converts aLocalDateTimeto ajava.sql.Timestamp.- Parameters:
dateTime- the local date-time, not null- Returns:
- the SQL timestamp, not null
-
toLocalDateTime
Converts ajava.sql.Timestampto aLocalDateTime.- Parameters:
sqlTimestamp- the SQL timestamp, not null- Returns:
- the local date-time, not null
-
toSqlTimestamp
Converts anInstantto ajava.sql.Timestamp.- Parameters:
instant- the instant, not null- Returns:
- the SQL timestamp, not null
-
toInstant
Converts ajava.sql.Timestampto anInstant.- Parameters:
sqlTimestamp- the SQL timestamp, not null- Returns:
- the instant, not null
-