SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
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

Mais conteúdo relacionado

Destaque

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
 

Destaque (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
 

Semelhante 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
 

Semelhante 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

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
🐬 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
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

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