Chi sono Federico Parezzan Ø Java backend developer Homo sum, humani nihil a me alienum puto ~ Terenzio federico-parezzan parez93
1. A look to the past 2. Java 8+ API 3. Demo 4. Database hints 5. Parsing and formatting hints 6. A little bit of infor-magic... 🤓 Agenda Agenda
1. Poor API design 2. Date as time interval 3. No Immutability 4. No Thread-Safe 5. Formatting classes work only with Date Date & Calendar A look to the past
1. API Clarity 2. Date as value 3. Immutability 4. Thread-Safe Java 8+ A look to the past
DEMO
API Java 8+ API java.time Meaning Time zoned Example LocalDate Date NO Current date LocalTime Time NO Current time LocalDateTime Date and time NO Start of a conference call in Italy ZonedDateTime Date and time YES Start of a conference call in America Duration Time between two instants NO Length of a meetup Period Amount of time in years, months and days NO Length of university studies Instant Specific moment in time YES Timestamp
DEMO LocalDate, LocalTime & LocalDateTime
DEMO ZonedDateTime
DEMO Instant
DEMO Period & Duration
Database types mapping Database hints SQL JAVA 8+ DATE LocalDate TIME LocalTime TIMESTAMP LocalDateTime TIME WITH TIME ZONE OffsetTime TIMESTAMP WITHOUT TIME ZONE OffsetDateTime
LocalDateTime dateTime = LocalDateTime.of(2020, 9, 1, 13, 14); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); String formattedDateTime = dateTime.format(formatter); System.out.println(formattedDateTime); LocalDateTime parsedDate = LocalDateTime.parse(formattedDateTime, formatter); System.out.println(parsedDate); Parsing & Formatting Parsing & Formatting
Cheatsheet Time to cheat
GRAZIE PER L’ATTENZIONE
 Migrating to the Java Date Time API version 8

Migrating to the Java Date Time API version 8

  • 2.
    Chi sono Federico Parezzan ØJava backend developer Homo sum, humani nihil a me alienum puto ~ Terenzio federico-parezzan parez93
  • 3.
    1. A lookto the past 2. Java 8+ API 3. Demo 4. Database hints 5. Parsing and formatting hints 6. A little bit of infor-magic... 🤓 Agenda Agenda
  • 4.
    1. Poor APIdesign 2. Date as time interval 3. No Immutability 4. No Thread-Safe 5. Formatting classes work only with Date Date & Calendar A look to the past
  • 5.
    1. API Clarity 2.Date as value 3. Immutability 4. Thread-Safe Java 8+ A look to the past
  • 6.
  • 7.
    API Java 8+ API java.timeMeaning Time zoned Example LocalDate Date NO Current date LocalTime Time NO Current time LocalDateTime Date and time NO Start of a conference call in Italy ZonedDateTime Date and time YES Start of a conference call in America Duration Time between two instants NO Length of a meetup Period Amount of time in years, months and days NO Length of university studies Instant Specific moment in time YES Timestamp
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
    Database types mapping Databasehints SQL JAVA 8+ DATE LocalDate TIME LocalTime TIMESTAMP LocalDateTime TIME WITH TIME ZONE OffsetTime TIMESTAMP WITHOUT TIME ZONE OffsetDateTime
  • 13.
    LocalDateTime dateTime =LocalDateTime.of(2020, 9, 1, 13, 14); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); String formattedDateTime = dateTime.format(formatter); System.out.println(formattedDateTime); LocalDateTime parsedDate = LocalDateTime.parse(formattedDateTime, formatter); System.out.println(parsedDate); Parsing & Formatting Parsing & Formatting
  • 14.
  • 15.