SlideShare una empresa de Scribd logo
1 de 13
Descargar para leer sin conexión
Java 8 Date Time
By Jim Gough

@JavaJimLondon
Agenda
•
•
•
•
•
•
•

Adopt a JSR

What exists in Java 7

New Things - The Basics

Working with Date and Time

Parsing and Formatting

Interoperability with java.util.Date

Advanced Queries
!2
Accompanying Materials
• Code along with github project:

• https:/
/github.com/jpgough/JavaTimeLab

!

• More information on my blog:

• http:/
/javajimlondon.blogspot.com/2014/01/
live-coding-on-java-8-date-time-api.html

!3
LJC/JCP
•

LJC elected onto the JCP committee


•

JCP (Java Community Process)

• The JCP is the mechanism for developing standard
technical specifications for the Java technology

!4
Adopt a JSR
•

This is it! JSR-310 is the pilot 


•

This program is intended to:

– Encourage members of the Java Community to get
involved in a JSR.

– Evangelise that JSR to the wider Java Community
community in order to increase grass roots
participation

– https:/
/java.net/projects/adoptajsr/pages/Home
Java Date
•

Java Date has been in the language since January 23,
1996


•

Many good discussions about what’s wrong with dates 


•

Mutability


•

Date is a DateTime, but there are other classes for SQL


•

No Timezones


•

Not easy to use

!6
Calendar
• Still mutable

• Can’t format a date directly

• Performing arithmetic operations on

dates not clearly supported. For
example time between two points

!7
Example From It’s High Time
@JavaOne 2008

•

How many bugs in this code?




Date date = new Date(2007, 12, 13, 16,
40); 




TimeZone zone =
TimeZone.getTimeZone("Asia/HongKong");




Calendar cal = new
GregorianCalendar(date, zone); 

DateFormat fm = new
SimpleDateFormat("HH:mm Z");

String str = fm.format(cal);
!8
Example From It’s High Time
@JavaOne 2008

•

6 bugs in the code!




Date date = new Date(2007, 12, 13, 16,
40); 




TimeZone zone =
TimeZone.getTimeZone("Asia/Hong_Kong");




Calendar cal = new
GregorianCalendar(date, zone); 

DateFormat fm = new
SimpleDateFormat("HH:mm Z");

String str = fm.format(cal);
!9
New Things - The Basics
•

New package java.time


•

New objects for representing Dates and Time

– LocalDate

– LocalTime

– LocalDateTime

– ZonedDateTime

!10
Working with Date and Time
•

Instant - Closest thing to java.util.Date


•

Duration

– Measure of time. Eg 34.5 seconds


•

Period

– A date based amount of time. Eg 5 days


•

Difference important when working with
ZonedDateTime operations.

!11
Java.util.Date
•

java.util.Date is actually closest to Instant


•

Now has to toInstant method on


•

Examples

!12
Parsing and Formatting
•

DateTimeFormatter


•

Nice predefined formatters:

– DateTimeFormatter.ISO_DATE


•

Can build a custom pattern

– Some slight modification to patterns


•

.format and .parse conveniently on objects.

!13

Más contenido relacionado

Destacado

Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8AppDynamics
 
Access PA and interlibrary loans
Access PA and interlibrary loansAccess PA and interlibrary loans
Access PA and interlibrary loansFrances Vita
 
14 generics and iterators
14   generics and iterators14   generics and iterators
14 generics and iteratorsTuan Ngo
 
Gartner iam 2011-analytics-aj-orig-recordednp-final
Gartner iam 2011-analytics-aj-orig-recordednp-finalGartner iam 2011-analytics-aj-orig-recordednp-final
Gartner iam 2011-analytics-aj-orig-recordednp-finalOracleIDM
 
Ley federal del trabaj1
Ley federal del trabaj1Ley federal del trabaj1
Ley federal del trabaj1AHOMEKIRA
 
Moviemaker 120104065957-phpapp01 - copy
Moviemaker 120104065957-phpapp01 - copyMoviemaker 120104065957-phpapp01 - copy
Moviemaker 120104065957-phpapp01 - copyAmka Anar
 
Copilarie fericita happy childhood
Copilarie fericita happy childhoodCopilarie fericita happy childhood
Copilarie fericita happy childhoodbalada65
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git MigrationTim Massey
 
Półmaraton 2013(1)
Półmaraton 2013(1)Półmaraton 2013(1)
Półmaraton 2013(1)franekmaster
 
KVH プラグ&トレード™
KVH プラグ&トレード™KVH プラグ&トレード™
KVH プラグ&トレード™KVH Co. Ltd.
 
BA Netapp Event - Always there IT Infrastructuur
BA Netapp Event - Always there IT InfrastructuurBA Netapp Event - Always there IT Infrastructuur
BA Netapp Event - Always there IT InfrastructuurB.A.
 
Health Tips by VisitHazara.Com
Health Tips by VisitHazara.ComHealth Tips by VisitHazara.Com
Health Tips by VisitHazara.ComMuneer Qureshi
 
Модель стратегического холдинга
Модель стратегического холдингаМодель стратегического холдинга
Модель стратегического холдингаАО "Самрук-Казына"
 
Mortimore Shonga Farms, Nigeria - An ‘experiment’ in large-scale commercial f...
Mortimore Shonga Farms, Nigeria - An ‘experiment’ in large-scale commercial f...Mortimore Shonga Farms, Nigeria - An ‘experiment’ in large-scale commercial f...
Mortimore Shonga Farms, Nigeria - An ‘experiment’ in large-scale commercial f...futureagricultures
 
Of mice and men2
Of mice and men2Of mice and men2
Of mice and men2NShuttle
 
WELL Explains: Kiss Sugar "Bye-Bye"!
WELL Explains: Kiss Sugar "Bye-Bye"!WELL Explains: Kiss Sugar "Bye-Bye"!
WELL Explains: Kiss Sugar "Bye-Bye"!Erin Michelle
 
#Beyondgender workshops
#Beyondgender workshops#Beyondgender workshops
#Beyondgender workshopsSon Vivienne
 

Destacado (20)

Introduzione a java doc
Introduzione a java docIntroduzione a java doc
Introduzione a java doc
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8
 
Access PA and interlibrary loans
Access PA and interlibrary loansAccess PA and interlibrary loans
Access PA and interlibrary loans
 
14 generics and iterators
14   generics and iterators14   generics and iterators
14 generics and iterators
 
Gartner iam 2011-analytics-aj-orig-recordednp-final
Gartner iam 2011-analytics-aj-orig-recordednp-finalGartner iam 2011-analytics-aj-orig-recordednp-final
Gartner iam 2011-analytics-aj-orig-recordednp-final
 
Ley federal del trabaj1
Ley federal del trabaj1Ley federal del trabaj1
Ley federal del trabaj1
 
Moviemaker 120104065957-phpapp01 - copy
Moviemaker 120104065957-phpapp01 - copyMoviemaker 120104065957-phpapp01 - copy
Moviemaker 120104065957-phpapp01 - copy
 
Copilarie fericita happy childhood
Copilarie fericita happy childhoodCopilarie fericita happy childhood
Copilarie fericita happy childhood
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
 
Półmaraton 2013(1)
Półmaraton 2013(1)Półmaraton 2013(1)
Półmaraton 2013(1)
 
KVH プラグ&トレード™
KVH プラグ&トレード™KVH プラグ&トレード™
KVH プラグ&トレード™
 
Traplate
TraplateTraplate
Traplate
 
BA Netapp Event - Always there IT Infrastructuur
BA Netapp Event - Always there IT InfrastructuurBA Netapp Event - Always there IT Infrastructuur
BA Netapp Event - Always there IT Infrastructuur
 
Health Tips by VisitHazara.Com
Health Tips by VisitHazara.ComHealth Tips by VisitHazara.Com
Health Tips by VisitHazara.Com
 
Volcanoes
VolcanoesVolcanoes
Volcanoes
 
Модель стратегического холдинга
Модель стратегического холдингаМодель стратегического холдинга
Модель стратегического холдинга
 
Mortimore Shonga Farms, Nigeria - An ‘experiment’ in large-scale commercial f...
Mortimore Shonga Farms, Nigeria - An ‘experiment’ in large-scale commercial f...Mortimore Shonga Farms, Nigeria - An ‘experiment’ in large-scale commercial f...
Mortimore Shonga Farms, Nigeria - An ‘experiment’ in large-scale commercial f...
 
Of mice and men2
Of mice and men2Of mice and men2
Of mice and men2
 
WELL Explains: Kiss Sugar "Bye-Bye"!
WELL Explains: Kiss Sugar "Bye-Bye"!WELL Explains: Kiss Sugar "Bye-Bye"!
WELL Explains: Kiss Sugar "Bye-Bye"!
 
#Beyondgender workshops
#Beyondgender workshops#Beyondgender workshops
#Beyondgender workshops
 

Similar a Introduction to Java 8 java.time

日本一細かいJavaOne2011報告
日本一細かいJavaOne2011報告日本一細かいJavaOne2011報告
日本一細かいJavaOne2011報告心 谷本
 
Jozi-JUG JDK 9 Unconference
Jozi-JUG JDK 9 UnconferenceJozi-JUG JDK 9 Unconference
Jozi-JUG JDK 9 UnconferenceHeather VanCura
 
Join the Java Evolution GIDS Bangalore & Pune
Join the Java Evolution GIDS Bangalore & PuneJoin the Java Evolution GIDS Bangalore & Pune
Join the Java Evolution GIDS Bangalore & PuneHeather VanCura
 
Join the Java Evolution Baltimore/DC/Philly
Join the Java Evolution Baltimore/DC/PhillyJoin the Java Evolution Baltimore/DC/Philly
Join the Java Evolution Baltimore/DC/PhillyHeather VanCura
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsC4Media
 
Join the Java Evolution Portland Oregon
Join the Java Evolution Portland OregonJoin the Java Evolution Portland Oregon
Join the Java Evolution Portland OregonHeather VanCura
 
JavaOne Latin America Participate in Shaping Java's Future
JavaOne Latin America Participate in Shaping Java's Future JavaOne Latin America Participate in Shaping Java's Future
JavaOne Latin America Participate in Shaping Java's Future Heather VanCura
 
Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)Hirofumi Iwasaki
 
Join the Java Evolution Columbus Ohio
Join the Java Evolution Columbus OhioJoin the Java Evolution Columbus Ohio
Join the Java Evolution Columbus OhioHeather VanCura
 
Join the Java Evolution NYC
Join the Java Evolution NYCJoin the Java Evolution NYC
Join the Java Evolution NYCHeather VanCura
 
Gaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGuillaume Laforge
 
Valencia EMEA Java User Group Summit
Valencia EMEA Java User Group SummitValencia EMEA Java User Group Summit
Valencia EMEA Java User Group SummitHeather VanCura
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合Kyle Lin
 
Pebank java handsout
Pebank java handsoutPebank java handsout
Pebank java handsoutPE-BANK
 
Migration strategies 4
Migration strategies 4Migration strategies 4
Migration strategies 4Wenhua Wang
 
Join the Java Evolution Coimbra
Join the Java Evolution CoimbraJoin the Java Evolution Coimbra
Join the Java Evolution CoimbraHeather VanCura
 

Similar a Introduction to Java 8 java.time (20)

日本一細かいJavaOne2011報告
日本一細かいJavaOne2011報告日本一細かいJavaOne2011報告
日本一細かいJavaOne2011報告
 
Jozi-JUG JDK 9 Unconference
Jozi-JUG JDK 9 UnconferenceJozi-JUG JDK 9 Unconference
Jozi-JUG JDK 9 Unconference
 
Join the Java Evolution GIDS Bangalore & Pune
Join the Java Evolution GIDS Bangalore & PuneJoin the Java Evolution GIDS Bangalore & Pune
Join the Java Evolution GIDS Bangalore & Pune
 
Join the Java Evolution Baltimore/DC/Philly
Join the Java Evolution Baltimore/DC/PhillyJoin the Java Evolution Baltimore/DC/Philly
Join the Java Evolution Baltimore/DC/Philly
 
Javantura v3 - The story of Java & HUJAK
Javantura v3 - The story of Java & HUJAKJavantura v3 - The story of Java & HUJAK
Javantura v3 - The story of Java & HUJAK
 
Java 8
Java 8Java 8
Java 8
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Join the Java Evolution Portland Oregon
Join the Java Evolution Portland OregonJoin the Java Evolution Portland Oregon
Join the Java Evolution Portland Oregon
 
JavaOne Latin America Participate in Shaping Java's Future
JavaOne Latin America Participate in Shaping Java's Future JavaOne Latin America Participate in Shaping Java's Future
JavaOne Latin America Participate in Shaping Java's Future
 
Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)
 
Join the Java Evolution Columbus Ohio
Join the Java Evolution Columbus OhioJoin the Java Evolution Columbus Ohio
Join the Java Evolution Columbus Ohio
 
Join the Java Evolution NYC
Join the Java Evolution NYCJoin the Java Evolution NYC
Join the Java Evolution NYC
 
Gaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume Laforge
 
Devoxx UK BOF session
Devoxx UK BOF sessionDevoxx UK BOF session
Devoxx UK BOF session
 
Valencia EMEA Java User Group Summit
Valencia EMEA Java User Group SummitValencia EMEA Java User Group Summit
Valencia EMEA Java User Group Summit
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合
 
Pebank java handsout
Pebank java handsoutPebank java handsout
Pebank java handsout
 
Migration strategies 4
Migration strategies 4Migration strategies 4
Migration strategies 4
 
Join the Java Evolution Coimbra
Join the Java Evolution CoimbraJoin the Java Evolution Coimbra
Join the Java Evolution Coimbra
 

Último

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Introduction to Java 8 java.time

  • 1. Java 8 Date Time By Jim Gough @JavaJimLondon
  • 2. Agenda • • • • • • • Adopt a JSR What exists in Java 7 New Things - The Basics Working with Date and Time Parsing and Formatting Interoperability with java.util.Date Advanced Queries !2
  • 3. Accompanying Materials • Code along with github project: • https:/ /github.com/jpgough/JavaTimeLab ! • More information on my blog: • http:/ /javajimlondon.blogspot.com/2014/01/ live-coding-on-java-8-date-time-api.html !3
  • 4. LJC/JCP • LJC elected onto the JCP committee • JCP (Java Community Process) • The JCP is the mechanism for developing standard technical specifications for the Java technology !4
  • 5. Adopt a JSR • This is it! JSR-310 is the pilot • This program is intended to: – Encourage members of the Java Community to get involved in a JSR. – Evangelise that JSR to the wider Java Community community in order to increase grass roots participation – https:/ /java.net/projects/adoptajsr/pages/Home
  • 6. Java Date • Java Date has been in the language since January 23, 1996 • Many good discussions about what’s wrong with dates • Mutability • Date is a DateTime, but there are other classes for SQL • No Timezones • Not easy to use !6
  • 7. Calendar • Still mutable • Can’t format a date directly • Performing arithmetic operations on dates not clearly supported. For example time between two points !7
  • 8. Example From It’s High Time @JavaOne 2008 • How many bugs in this code?
 
 Date date = new Date(2007, 12, 13, 16, 40); 
 
 TimeZone zone = TimeZone.getTimeZone("Asia/HongKong");
 
 Calendar cal = new GregorianCalendar(date, zone); 
 DateFormat fm = new SimpleDateFormat("HH:mm Z");
 String str = fm.format(cal); !8
  • 9. Example From It’s High Time @JavaOne 2008 • 6 bugs in the code!
 
 Date date = new Date(2007, 12, 13, 16, 40); 
 
 TimeZone zone = TimeZone.getTimeZone("Asia/Hong_Kong");
 
 Calendar cal = new GregorianCalendar(date, zone); 
 DateFormat fm = new SimpleDateFormat("HH:mm Z");
 String str = fm.format(cal); !9
  • 10. New Things - The Basics • New package java.time • New objects for representing Dates and Time – LocalDate – LocalTime – LocalDateTime – ZonedDateTime !10
  • 11. Working with Date and Time • Instant - Closest thing to java.util.Date • Duration – Measure of time. Eg 34.5 seconds • Period – A date based amount of time. Eg 5 days • Difference important when working with ZonedDateTime operations. !11
  • 12. Java.util.Date • java.util.Date is actually closest to Instant • Now has to toInstant method on • Examples !12
  • 13. Parsing and Formatting • DateTimeFormatter • Nice predefined formatters: – DateTimeFormatter.ISO_DATE • Can build a custom pattern – Some slight modification to patterns • .format and .parse conveniently on objects. !13