Core Java Advanced LiveLessons

Date and Time

Copyright © Cay S. Horstmann 2016

Understand the challenges of computing with dates and times

Challenges of Date and Time Processing

Work with instants and durations

Instants

Durations

Use the Java classes for local dates and times

Local Dates

jshell

import java.time.*

LocalDate today = LocalDate.now()
today.plusDays(100)
today.plusDays(1000)
LocalDate birthday = LocalDate.of(1961, 8, 4)

import java.time.temporal.*

birthday.until(today, ChronoUnit.DAYS)

Weekdays

Date Adjusters

lesson08/adjusters

Local Time

Be able to handle time zones

Zoned Time

Daylight Savings Time

jshell

ZonedDateTime.now()
ZonedDateTime.now(ZoneId.of("UTC"))
ZonedDateTime.now(ZoneId.of("Europe/Rome"))

ZonedDateTime.now().plus(Duration.ofDays(90))
ZonedDateTime.now().plus(Period.ofDays(90))

Interoperate with legacy date and time classes

Legacy Date and Time Classes