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

Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with ClojureJohn Stevenson
 
Short history of time - Confitura 2013
Short history of time - Confitura 2013Short history of time - Confitura 2013
Short history of time - Confitura 2013nurkiewicz
 
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 FlinkDongwon Kim
 
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 sparkDemi 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
 
Reactive Programming and RxJS
Reactive Programming and RxJSReactive Programming and RxJS
Reactive Programming and RxJSDenis Gorbunov
 
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 FlinkDongwon Kim
 
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/IIPeter Csala
 
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

Java 8 date & time javaday2014
Java 8 date & time javaday2014Java 8 date & time javaday2014
Java 8 date & time javaday2014Oleg Tsal-Tsalko
 
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 patternsAntonio García-Domínguez
 
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 ApplicationMark Stoodley
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to ApexSujit Kumar
 
Mr. Keil Werner - UOMO 2011
Mr. Keil Werner - UOMO 2011Mr. Keil Werner - UOMO 2011
Mr. Keil Werner - UOMO 2011beloslab
 
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 programmingHenri Tremblay
 
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 ...NETWAYS
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
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.ASIT Education
 
Journey towards serverless infrastructure
Journey towards serverless infrastructureJourney towards serverless infrastructure
Journey towards serverless infrastructureVille Seppänen
 
MODULE IV embedded (1).pptx
MODULE IV embedded (1).pptxMODULE IV embedded (1).pptx
MODULE IV embedded (1).pptxSajinvs4
 
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 3Kenji HASUNUMA
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Simon Ritter
 
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 3Kenji HASUNUMA
 

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

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)Oleg Tsal-Tsalko
 
From Streams to Reactive Streams
From Streams to Reactive StreamsFrom Streams to Reactive Streams
From Streams to Reactive StreamsOleg Tsal-Tsalko
 
JUG UA AdoptJSR participation
JUG UA AdoptJSR participationJUG UA AdoptJSR participation
JUG UA AdoptJSR participationOleg Tsal-Tsalko
 
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 Oleg Tsal-Tsalko
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration PatternsOleg Tsal-Tsalko
 
Distributed systems and scalability rules
Distributed systems and scalability rulesDistributed systems and scalability rules
Distributed systems and scalability rulesOleg Tsal-Tsalko
 
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 programOleg 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

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
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.pdfkalichargn70th171
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
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.comFatema Valibhai
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
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.docxComplianceQuest1
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
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
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
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
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
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
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 

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