JavaSE进阶

10.8.4 与传统日期处理的转换

To 遗留类

From 遗留类

java.time.Instantjava.util.Date

Date.from(instant)

date.toInstant()

java.time.Instantjava.sql.Timestamp

Timestamp.from(instant)

timestamp.toInstant()

java.time.ZonedDateTimejava.util.GregorianCalendar

GregorianCalendar.from(zonedDateTime)

cal.toZonedDateTime()

java.time.LocalDatejava.sql.Time

Date.valueOf(localDate)

date.toLocalDate()

java.time.LocalTimejava.sql.Time

Date.valueOf(localDate)

date.toLocalTime()

java.time.LocalDateTimejava.sql.Timestamp

Timestamp.valueOf(localDateTime)

timestamp.toLocalDateTime()

java.time.ZoneIdjava.util.TimeZone

Timezone.getTimeZone(id)

timeZone.toZoneId()

java.time.format.DateTimeFormatterjava.text.DateFormat

formatter.toFormat()