Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Date time java 8 (jsr 310)

3,532 views

Published on

A presentation I did in IL Java User Group about Java 8, DateTime new features. JSR-310

I wanted it to be informative and a good resource and starting point for this cool feature.

Published in: Software
  • Hello! I can recommend a site that has helped me. It's called ⇒ HelpWriting.net ⇐ They helped me for writing my quality research paper on diabetes, and of course by keeping my all other needs fulfilled.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • ..............ACCESS that WEBSITE Over for All Ebooks ................ ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Date time java 8 (jsr 310)

  1. 1. Date Time Java 8 (JSR-310) ilJUG – July 2014 By: Eyal Golan Tech Lead at eBay
  2. 2. A word before starting… The intent of this presentation is to be basic source and starting point to the new Java Date Time API (JSR-310) 2
  3. 3. Agenda • Old vs. New • JSR 310 • Examples by code • Resources 3
  4. 4. Old Issues • Date is not a date, nor time. It’s an instant in time (by epoch) • Calendar is Date and Time • Month is 0 (zero) based • Mutability 4
  5. 5. Example – Issues 5
  6. 6. Example – Issues 6
  7. 7. Example – Issues 7 First try=1274 , second try=0 Use (Calendar)start.clone();
  8. 8. Calendar • YEAR, MONTH, DAY_OF_MONTH… • Fields start at 0 • Calendar is mutable • Methods (set, add…) change the state of Calendar 8
  9. 9. Example – The New Way 9 1274
  10. 10. Example – The New Way 10 1274
  11. 11. Example – The New Way 11 1274
  12. 12. Example – The New Way 12 Today 2014-07-29 and next year 2015-07-29
  13. 13. Modeling • Different date/time scenarios • Class starts at 12:30 • ilJUG is on 29th July • The presentation is 1 hour long • I’ve been working at eBay for 3 years and 6 months 13
  14. 14. Example – Issues 14
  15. 15. Example – The New Way 15
  16. 16. Example – The New Way 16
  17. 17. Amount of Time • How many milliseconds it took between request to response? • Set time 10 seconds after now • Calculate time that passed between two events 17
  18. 18. Example – Old Calculation 18 now Tue Jul 29 01:48:56 IDT 2014 and later Thu Jan 01 04:20:00 IST 1970
  19. 19. Example – Old Calculation 19 119 days 6 hours 13 minutes 24 seconds 543 ms Example taken from stackoverflow
  20. 20. Duration and Period 20
  21. 21. Duration – Machine Time 21 now 2014-07-28T23:17:40.898Z and later 2014-07-29T01:47:40.898Z 150 2014-07-28T23:17:53.898Z 9000000
  22. 22. Period – Human Time 22
  23. 23. Guidelines • Clear • Fluent • DSL • Immutability • Amount of time, different representations for different cases • Human (year, month, day) • Machine time 24
  24. 24. Packages • java.time • java.time.chrono • java.time.format • java.time.temporal • java.time.zone 25
  25. 25. Some (not all) Classes • Temporal – Basic interface for DateTime classes • LocalDate / LocalTime / LocalDateTime … • Instant • Start of nanoseconds in timeline. Useful for timestamp • Clock • Allowing Temporal creation with alternate clock • TemporalAmount – Basic interface for classes that represent amount of time • Duration • Period 26
  26. 26. Methods Naming Conventions of Static Creates an instance with validation to Instance Converts to another type (truncate fields) at Instance Combines this object with another (expands) from Static Converts input parameters to an instance get Instance Part of the state of the object 27
  27. 27. Methods Naming Conventions is Instance Queries state of an object with Instance Returns a copy of an object with one changed element plus / minus instance Returns a copy of an object with amount of added / subtracted time parse Static Parses input string to an instance format Instance Uses formatter to format the object’s values to produce a string 28
  28. 28. Source Code 30 https://github.com/eyalgo/java8-datetime
  29. 29. General 31 SystemClock[Asia/Jerusalem] 2014-07-29T05:54:23.337 2014-07-29T08:54:23.338 SystemClock[Asia/Jerusalem] SystemClock[Europe/Berlin] 2014-7-29
  30. 30. General 32 SystemClock[Asia/Jerusalem] 2014-07-29T05:54:23.337 2014-07-29T08:54:23.338 SystemClock[Asia/Jerusalem] SystemClock[Europe/Berlin] 2014-7-29
  31. 31. General 33 SystemClock[Asia/Jerusalem] 2014-07-29T05:54:23.337 2014-07-29T08:54:23.338 SystemClock[Asia/Jerusalem] SystemClock[Europe/Berlin] 2014-7-29
  32. 32. The Basics 34
  33. 33. Basic Date and Time 35
  34. 34. Partial Dates & Information 36
  35. 35. Information, Clear API 37
  36. 36. Fluent Operations 38
  37. 37. Time Zone 39
  38. 38. Using Zone 40
  39. 39. Instant 41 From Javadoc: "This class models a single instantaneous point on the time-line. This might be used to record event time-stamps in the application... "...number of seconds that can be held in a long. This is greater than the current estimated age of the universe... "...The instant is stored to nanosecond resolution..."
  40. 40. Adjusters • Take Temporal value and adjust it • Pre defined • firstDayOfMonth • firstDayOfYear • lastInMonth • Look at TemoralAdjusters • Custom adjusters 42
  41. 41. Adjusters 43
  42. 42. Custom Adjusters 44 2014-08-05 2009-09-01
  43. 43. Queries – Retrieve Information 45
  44. 44. Custom Queries 46
  45. 45. Custom Queries 47
  46. 46. Parsing and Formatting • DateTimeFormatter • Many pre defined formats • http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#predefined • Immutable • DateTimeFormatterBuilder • All classes use the same way • DateTimeParseException (runtime) 48
  47. 47. Parsing and Formatting 49 07**2014--16
  48. 48. Legacy Date Time Integration 50
  49. 49. 52 https://github.com/eyalgo/java8-datetime http://docs.oracle.com/javase/tutorial/datetime/iso/index.html http://docs.oracle.com/javase/tutorial/datetime/index.html https://jcp.org/en/jsr/detail?id=310 http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html http://www.mscharhag.com/2014/02/java-8-datetime-api.html http://geekmonkey.org/articles/24-a-new-date-and-time-api-for-jdk-8 https://today.java.net/pub/a/today/2008/09/18/jsr-310-new-java-date-time-api.html
  50. 50. egolan74@gmail.com https://www.linkedin.com/in/egolan74 http://eyalgo.com/ @eyalgo_egolan

×