SlideShare a Scribd company logo
1 of 18
Download to read offline
Speaker:	
  Oleg	
  Tsal-­‐Tsalko(@tsaltsol)	
  
Java	
  8	
  Date	
  &	
  Time	
  API	
  
(based	
  on	
  Stephen	
  Colebourne	
  Java	
  8	
  launch	
  talk)	
  
About	
  me	
  
Oleg	
  Tsal-­‐Tsalko	
  
Lead	
  So:ware	
  Engineer	
  at	
  EPAM	
  Systems.	
  
Speaker,	
  acEve	
  member	
  of	
  Kiev	
  JUG.	
  
ParEcipate	
  in	
  different	
  educaEonal	
  
iniEaEves	
  and	
  JCP/AdoptJSR	
  programs.	
  
Overview	
  
•  JSR-­‐310:	
  New	
  Date	
  &	
  Time	
  API	
  
•  Replaces	
  old	
  ambiguous	
  java.uEl.Date,	
  
Calendar,	
  TimeZone,	
  DateFormat	
  classes	
  
•  More	
  fluent/simple/clean	
  API	
  
•  Immutable	
  classes	
  
•  Using	
  Java8	
  features	
  including	
  lambdas	
  
•  Precise	
  separaEon	
  of	
  concepts	
  
Range	
  of	
  types	
  
•  LocalDate	
  –	
  a	
  date	
  only	
  
•  LocalTime	
  –	
  a	
  Eme	
  only	
  
•  LocalDateTime	
  –	
  date	
  with	
  Eme	
  
•  ZonedDateTime	
  –	
  date	
  with	
  Eme	
  in	
  Eme	
  zone	
  
•  And	
  more…	
  
LocalDate	
  
Stores	
  year-­‐month-­‐day	
  
Use	
  cases:	
  birthdays,	
  start/end	
  dates,	
  holidays	
  
dates	
  
	
  
LocalDate	
  current	
  =	
  LocalDate.now();	
  
LocalDate	
  date	
  =	
  LocalDate.of(2014,	
  Month.AUGUST,	
  10);	
  
	
  
If	
  (current.isA:er(date))…	
  
	
  
boolean	
  leap	
  =	
  date.isLeapYear();	
  
int	
  monthLength	
  =	
  date.lengthOfMonth();	
  
Dates	
  manipulaEon	
  
Because	
  LocalDate	
  is	
  immutable	
  	
  
we	
  have	
  plus/minus/with	
  methods	
  	
  
instead	
  add/set	
  methods:	
  
	
  
date	
  =	
  date.plusMonth(1).minusDays(5);	
  
date	
  =	
  date.withDayOfMonth(1);	
  
date	
  =	
  date.with(Month.SEPTEMBER);	
  
Using	
  adjusters	
  
For	
  more	
  complex	
  dates	
  manipulaEons	
  we	
  use	
  
many	
  predefined	
  TemporalAdjusters	
  or	
  create	
  
custom	
  ones:	
  
date	
  =	
  date.with(TemporalAdjusters.lastDayOfMonth());	
  
date	
  =	
  date.with(next(TUESDAY))	
  
LocalTime	
  
Stores	
  hour-­‐minute-­‐second-­‐nanosecond	
  
Use	
  cases:	
  shop	
  openning	
  hous,	
  clock	
  alarms,	
  
etc.	
  
	
  
LocalTime	
  current	
  =	
  LocalTime.now();	
  
LocalTime	
  Eme	
  =	
  LocalTime.of(13,30);	
  
	
  
If	
  (current.isBefore(Eme))	
  …	
  
	
  
Eme	
  =	
  Eme.plusHours(4).plusMinutes(10).minusSeconds(30);	
  
Eme	
  =	
  Eme.truncatedTo(SECONDS);	
  
LocalDateTime	
  
Basically	
  combinaEon	
  of	
  LocalDate	
  and	
  LocalTime.	
  	
  
All	
  methods	
  are	
  similar	
  to	
  LocalDate	
  and	
  LocalTime…	
  
TimeZones	
  
We	
  have	
  numerous	
  of	
  TimeZones	
  	
  
governed	
  by	
  poliIcal	
  rules	
  	
  
which	
  someEmes	
  complex	
  	
  
and	
  might	
  change	
  frequently.	
  
	
  
If	
  you	
  can	
  avoid	
  using	
  TimeZones	
  –	
  do	
  it!	
  
TimeZone	
  classes	
  in	
  Java	
  8	
  
•  ZoneId	
  –	
  replacement	
  for	
  TimeZone	
  class	
  (e.g.	
  
“Europe/London”,	
  “Europe/Kiev”)	
  
•  ZoneOffset	
  –	
  represenEng	
  offset	
  from	
  UTC	
  
Eme	
  
•  ZoneRules	
  –	
  behind	
  the	
  scenes	
  class	
  which	
  
defines	
  Eme	
  zone	
  rules	
  
•  ZonedDateTime	
  –	
  main	
  date/Eme	
  class	
  which	
  
is	
  aware	
  of	
  Eme	
  zones	
  
ZonedDateTime	
  
Internaly	
  stores	
  LocalDateTime,	
  ZoneId	
  and	
  ZoneOffset	
  
and	
  is	
  closest	
  equivalent	
  to	
  java.u2l.GregorianCalendar.	
  
zone	
  =	
  ZoneId.of(“Europe/London”);	
  
zonedDateTime	
  =	
  ZonedDateTime.of(2014,	
  AUGUST,	
  
10,	
  13,	
  30,	
  0,	
  0,	
  zone);	
  
zonedDateTime.plusDays(1).minusMinutes(30);	
  
	
  
Takes	
  care	
  of	
  ‘daylight	
  savings’	
  	
  
and	
  no	
  excepEons	
  thrown	
  in	
  ambigue	
  cases	
  	
  
instead	
  act	
  on	
  best	
  effort	
  basis	
  
Calendar	
  systems	
  
•  All	
  main	
  classes	
  use	
  ISO	
  calendar	
  system	
  
•  Other	
  calendar	
  systems	
  (Hijrah,	
  Japanese,	
  
Minguo,	
  ThaiBuddist,	
  etc.)	
  also	
  supported	
  
however	
  not	
  at	
  the	
  same	
  degree	
  and	
  might	
  be	
  
complicated	
  to	
  use.	
  
•  Good	
  thong	
  is	
  that	
  diff	
  calendar	
  systems	
  
separated	
  from	
  each	
  other	
  
•  Main	
  interfaces	
  to	
  be	
  implemented	
  for	
  new	
  
calendar	
  systems	
  are:	
  Cronology	
  and	
  
ChronoLocalDate	
  
Power	
  of	
  abstracEon	
  
New	
  API	
  is	
  very	
  flexible	
  because	
  it	
  based	
  on	
  number	
  of	
  
abstracEons	
  at	
  it’s	
  bopom:	
  
•  Temporal	
  –	
  parent	
  class	
  for	
  all	
  date/Eme	
  objects	
  which	
  
defines	
  mutaEon	
  operaEon	
  for	
  them	
  such	
  as	
  plus/
minus/with	
  
•  TemporalAdjuster	
  –	
  funcEonal	
  interface	
  which	
  
responsible	
  for	
  mutaEng	
  Temporal	
  objects	
  
•  TemporalField	
  –	
  represents	
  parts/fields	
  of	
  date/Eme	
  
objects	
  such	
  as	
  (DAY_OF_WEEK,	
  MONTH,	
  etc.)	
  
•  TemporalUnit	
  –	
  represents	
  type	
  of	
  date/Eme	
  values	
  
such	
  as	
  (MINUTES,	
  DAYS,	
  YEARS,	
  etc.)	
  
•  TemporalAmount	
  –	
  class	
  which	
  represents	
  amount	
  of	
  
Eme	
  
DuraEon	
  
Time-­‐based	
  amount	
  of	
  Eme	
  in	
  hours,	
  minutes,	
  
seconds	
  or	
  nanoseconds.	
  
Use	
  cases:	
  Emeouts	
  
	
  
duraEon	
  =	
  DuraEon.ofHours(6);	
  
duraEon	
  =	
  duraEon.mulEpliedBy(3);	
  
duraEon	
  =	
  duraEon.plusMinutes(30);	
  
	
  
date	
  =	
  LocalDateTime.now();	
  
Date.plus(duraEon);	
  
Period	
  
Date-­‐based	
  amount	
  of	
  Eme	
  in	
  years,	
  months,	
  
days.	
  
Use	
  cases:	
  length	
  of	
  holiday,	
  length	
  of	
  	
  trip	
  
	
  
period	
  =	
  Period.ofMonth(9);	
  
period	
  =	
  period.plusDays(6);	
  
Links	
  
•  hpps://today.java.net/pub/a/today/2008/09/18/
jsr-­‐310-­‐new-­‐java-­‐date-­‐Eme-­‐api.html	
  
•  hpp://blog.joda.org/2009/11/why-­‐jsr-­‐310-­‐isn-­‐
joda-­‐Eme_4941.html	
  
•  hpps://blogs.oracle.com/thejavatutorials/entry/
javaone_2013_jdk_8_date	
  
•  hpp://vimeo.com/87157763	
  
•  hpp://parleys.com/play/
52508380e4b0c4f11ec57665/about	
  
•  hpp://www.oracle.com/events/us/en/java8/
index.html	
  
Thank	
  you!	
  
Oleg	
  Tsal-­‐Tsalko	
  
Email:	
  oleg.tsalko@gmail.com	
  
Twiper:	
  @tsaltsol	
  
	
  
	
  
	
  

More Related Content

What's hot

Short history of time - Confitura 2013
Short history of time - Confitura 2013Short history of time - Confitura 2013
Short history of time - Confitura 2013
nurkiewicz
 
Scala like distributed collections - dumping time-series data with apache spark
Scala like distributed collections - dumping time-series data with apache sparkScala like distributed collections - dumping time-series data with apache spark
Scala like distributed collections - dumping time-series data with apache spark
Demi Ben-Ari
 
Scalable Realtime Analytics with declarative SQL like Complex Event Processin...
Scalable Realtime Analytics with declarative SQL like Complex Event Processin...Scalable Realtime Analytics with declarative SQL like Complex Event Processin...
Scalable Realtime Analytics with declarative SQL like Complex Event Processin...
Srinath Perera
 
Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...
Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...
Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...
Lucidworks
 

What's hot (11)

Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
 
Fun times with ruby
Fun times with rubyFun times with ruby
Fun times with ruby
 
Short history of time - Confitura 2013
Short history of time - Confitura 2013Short history of time - Confitura 2013
Short history of time - Confitura 2013
 
Real-time driving score service using Flink
Real-time driving score service using FlinkReal-time driving score service using Flink
Real-time driving score service using Flink
 
Scala like distributed collections - dumping time-series data with apache spark
Scala like distributed collections - dumping time-series data with apache sparkScala like distributed collections - dumping time-series data with apache spark
Scala like distributed collections - dumping time-series data with apache spark
 
Scalable Realtime Analytics with declarative SQL like Complex Event Processin...
Scalable Realtime Analytics with declarative SQL like Complex Event Processin...Scalable Realtime Analytics with declarative SQL like Complex Event Processin...
Scalable Realtime Analytics with declarative SQL like Complex Event Processin...
 
Reactive Programming and RxJS
Reactive Programming and RxJSReactive Programming and RxJS
Reactive Programming and RxJS
 
Predictive Maintenance with Deep Learning and Apache Flink
Predictive Maintenance with Deep Learning and Apache FlinkPredictive Maintenance with Deep Learning and Apache Flink
Predictive Maintenance with Deep Learning and Apache Flink
 
Akka-demy (a.k.a. How to build stateful distributed systems) I/II
 Akka-demy (a.k.a. How to build stateful distributed systems) I/II Akka-demy (a.k.a. How to build stateful distributed systems) I/II
Akka-demy (a.k.a. How to build stateful distributed systems) I/II
 
Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...
Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...
Faceting Optimizations for Solr: Presented by Toke Eskildsen, State & Univers...
 
Apache Storm
Apache StormApache Storm
Apache Storm
 

Similar to Java 8 date & time

Mr. Keil Werner - UOMO 2011
Mr. Keil Werner - UOMO 2011Mr. Keil Werner - UOMO 2011
Mr. Keil Werner - UOMO 2011
beloslab
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 

Similar to Java 8 date & time (20)

Java 8 date & time javaday2014
Java 8 date & time javaday2014Java 8 date & time javaday2014
Java 8 date & time javaday2014
 
Java utility classes
Java utility classesJava utility classes
Java utility classes
 
MODELS 2019: Querying and annotating model histories with time-aware patterns
MODELS 2019: Querying and annotating model histories with time-aware patternsMODELS 2019: Querying and annotating model histories with time-aware patterns
MODELS 2019: Querying and annotating model histories with time-aware patterns
 
Eliminating the Pauses in your Java Application
Eliminating the Pauses in your Java ApplicationEliminating the Pauses in your Java Application
Eliminating the Pauses in your Java Application
 
Rtos ss
Rtos ssRtos ss
Rtos ss
 
Elixir
ElixirElixir
Elixir
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to Apex
 
Mr. Keil Werner - UOMO 2011
Mr. Keil Werner - UOMO 2011Mr. Keil Werner - UOMO 2011
Mr. Keil Werner - UOMO 2011
 
Java 8
Java 8Java 8
Java 8
 
DevNexus 2018: Learn Java 8, lambdas and functional programming
DevNexus 2018: Learn Java 8, lambdas and functional programmingDevNexus 2018: Learn Java 8, lambdas and functional programming
DevNexus 2018: Learn Java 8, lambdas and functional programming
 
OSDC 2018 | Lifecycle of a resource. Codifying infrastructure with Terraform ...
OSDC 2018 | Lifecycle of a resource. Codifying infrastructure with Terraform ...OSDC 2018 | Lifecycle of a resource. Codifying infrastructure with Terraform ...
OSDC 2018 | Lifecycle of a resource. Codifying infrastructure with Terraform ...
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.
 
JavaOne 2011 Recap
JavaOne 2011 RecapJavaOne 2011 Recap
JavaOne 2011 Recap
 
Journey towards serverless infrastructure
Journey towards serverless infrastructureJourney towards serverless infrastructure
Journey towards serverless infrastructure
 
MODULE IV embedded (1).pptx
MODULE IV embedded (1).pptxMODULE IV embedded (1).pptx
MODULE IV embedded (1).pptx
 
gcdtmp
gcdtmpgcdtmp
gcdtmp
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
 

More from Oleg Tsal-Tsalko

More from Oleg Tsal-Tsalko (13)

Developer on a mission (Devoxx UA 2021)
Developer on a mission (Devoxx UA 2021)Developer on a mission (Devoxx UA 2021)
Developer on a mission (Devoxx UA 2021)
 
Developer on a mission
Developer on a missionDeveloper on a mission
Developer on a mission
 
From Streams to Reactive Streams
From Streams to Reactive StreamsFrom Streams to Reactive Streams
From Streams to Reactive Streams
 
Java 9 Jigsaw HackDay
Java 9 Jigsaw HackDayJava 9 Jigsaw HackDay
Java 9 Jigsaw HackDay
 
JUG UA AdoptJSR participation
JUG UA AdoptJSR participationJUG UA AdoptJSR participation
JUG UA AdoptJSR participation
 
Develop modern apps using Spring ecosystem at time of BigData
Develop modern apps using Spring ecosystem at time of BigData Develop modern apps using Spring ecosystem at time of BigData
Develop modern apps using Spring ecosystem at time of BigData
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Lambdas HOL
Lambdas HOLLambdas HOL
Lambdas HOL
 
Get ready for spring 4
Get ready for spring 4Get ready for spring 4
Get ready for spring 4
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration Patterns
 
Distributed systems and scalability rules
Distributed systems and scalability rulesDistributed systems and scalability rules
Distributed systems and scalability rules
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
JUG involvment in JCP and AdopJSR program
JUG involvment in JCP and AdopJSR programJUG involvment in JCP and AdopJSR program
JUG involvment in JCP and AdopJSR program
 

Recently uploaded

Recently uploaded (20)

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Java 8 date & time

  • 1. Speaker:  Oleg  Tsal-­‐Tsalko(@tsaltsol)   Java  8  Date  &  Time  API   (based  on  Stephen  Colebourne  Java  8  launch  talk)  
  • 2. About  me   Oleg  Tsal-­‐Tsalko   Lead  So:ware  Engineer  at  EPAM  Systems.   Speaker,  acEve  member  of  Kiev  JUG.   ParEcipate  in  different  educaEonal   iniEaEves  and  JCP/AdoptJSR  programs.  
  • 3. Overview   •  JSR-­‐310:  New  Date  &  Time  API   •  Replaces  old  ambiguous  java.uEl.Date,   Calendar,  TimeZone,  DateFormat  classes   •  More  fluent/simple/clean  API   •  Immutable  classes   •  Using  Java8  features  including  lambdas   •  Precise  separaEon  of  concepts  
  • 4. Range  of  types   •  LocalDate  –  a  date  only   •  LocalTime  –  a  Eme  only   •  LocalDateTime  –  date  with  Eme   •  ZonedDateTime  –  date  with  Eme  in  Eme  zone   •  And  more…  
  • 5. LocalDate   Stores  year-­‐month-­‐day   Use  cases:  birthdays,  start/end  dates,  holidays   dates     LocalDate  current  =  LocalDate.now();   LocalDate  date  =  LocalDate.of(2014,  Month.AUGUST,  10);     If  (current.isA:er(date))…     boolean  leap  =  date.isLeapYear();   int  monthLength  =  date.lengthOfMonth();  
  • 6. Dates  manipulaEon   Because  LocalDate  is  immutable     we  have  plus/minus/with  methods     instead  add/set  methods:     date  =  date.plusMonth(1).minusDays(5);   date  =  date.withDayOfMonth(1);   date  =  date.with(Month.SEPTEMBER);  
  • 7. Using  adjusters   For  more  complex  dates  manipulaEons  we  use   many  predefined  TemporalAdjusters  or  create   custom  ones:   date  =  date.with(TemporalAdjusters.lastDayOfMonth());   date  =  date.with(next(TUESDAY))  
  • 8. LocalTime   Stores  hour-­‐minute-­‐second-­‐nanosecond   Use  cases:  shop  openning  hous,  clock  alarms,   etc.     LocalTime  current  =  LocalTime.now();   LocalTime  Eme  =  LocalTime.of(13,30);     If  (current.isBefore(Eme))  …     Eme  =  Eme.plusHours(4).plusMinutes(10).minusSeconds(30);   Eme  =  Eme.truncatedTo(SECONDS);  
  • 9. LocalDateTime   Basically  combinaEon  of  LocalDate  and  LocalTime.     All  methods  are  similar  to  LocalDate  and  LocalTime…  
  • 10. TimeZones   We  have  numerous  of  TimeZones     governed  by  poliIcal  rules     which  someEmes  complex     and  might  change  frequently.     If  you  can  avoid  using  TimeZones  –  do  it!  
  • 11. TimeZone  classes  in  Java  8   •  ZoneId  –  replacement  for  TimeZone  class  (e.g.   “Europe/London”,  “Europe/Kiev”)   •  ZoneOffset  –  represenEng  offset  from  UTC   Eme   •  ZoneRules  –  behind  the  scenes  class  which   defines  Eme  zone  rules   •  ZonedDateTime  –  main  date/Eme  class  which   is  aware  of  Eme  zones  
  • 12. ZonedDateTime   Internaly  stores  LocalDateTime,  ZoneId  and  ZoneOffset   and  is  closest  equivalent  to  java.u2l.GregorianCalendar.   zone  =  ZoneId.of(“Europe/London”);   zonedDateTime  =  ZonedDateTime.of(2014,  AUGUST,   10,  13,  30,  0,  0,  zone);   zonedDateTime.plusDays(1).minusMinutes(30);     Takes  care  of  ‘daylight  savings’     and  no  excepEons  thrown  in  ambigue  cases     instead  act  on  best  effort  basis  
  • 13. Calendar  systems   •  All  main  classes  use  ISO  calendar  system   •  Other  calendar  systems  (Hijrah,  Japanese,   Minguo,  ThaiBuddist,  etc.)  also  supported   however  not  at  the  same  degree  and  might  be   complicated  to  use.   •  Good  thong  is  that  diff  calendar  systems   separated  from  each  other   •  Main  interfaces  to  be  implemented  for  new   calendar  systems  are:  Cronology  and   ChronoLocalDate  
  • 14. Power  of  abstracEon   New  API  is  very  flexible  because  it  based  on  number  of   abstracEons  at  it’s  bopom:   •  Temporal  –  parent  class  for  all  date/Eme  objects  which   defines  mutaEon  operaEon  for  them  such  as  plus/ minus/with   •  TemporalAdjuster  –  funcEonal  interface  which   responsible  for  mutaEng  Temporal  objects   •  TemporalField  –  represents  parts/fields  of  date/Eme   objects  such  as  (DAY_OF_WEEK,  MONTH,  etc.)   •  TemporalUnit  –  represents  type  of  date/Eme  values   such  as  (MINUTES,  DAYS,  YEARS,  etc.)   •  TemporalAmount  –  class  which  represents  amount  of   Eme  
  • 15. DuraEon   Time-­‐based  amount  of  Eme  in  hours,  minutes,   seconds  or  nanoseconds.   Use  cases:  Emeouts     duraEon  =  DuraEon.ofHours(6);   duraEon  =  duraEon.mulEpliedBy(3);   duraEon  =  duraEon.plusMinutes(30);     date  =  LocalDateTime.now();   Date.plus(duraEon);  
  • 16. Period   Date-­‐based  amount  of  Eme  in  years,  months,   days.   Use  cases:  length  of  holiday,  length  of    trip     period  =  Period.ofMonth(9);   period  =  period.plusDays(6);  
  • 17. Links   •  hpps://today.java.net/pub/a/today/2008/09/18/ jsr-­‐310-­‐new-­‐java-­‐date-­‐Eme-­‐api.html   •  hpp://blog.joda.org/2009/11/why-­‐jsr-­‐310-­‐isn-­‐ joda-­‐Eme_4941.html   •  hpps://blogs.oracle.com/thejavatutorials/entry/ javaone_2013_jdk_8_date   •  hpp://vimeo.com/87157763   •  hpp://parleys.com/play/ 52508380e4b0c4f11ec57665/about   •  hpp://www.oracle.com/events/us/en/java8/ index.html  
  • 18. Thank  you!   Oleg  Tsal-­‐Tsalko   Email:  oleg.tsalko@gmail.com   Twiper:  @tsaltsol