Java
Date and Time
Past and Future
Iulian Dogariu
Ness Technologies
Iași Java User Group
1379518200000
APIs that make me happy
Timestamp
“System.currentTimeMillis() should be
enough for anybody”
-- Bill Gates,
after seeing the JDK 1.0 Javadocs
(well, not real...
java.util.Date
java.util.Calendar
POLA !
java.util.Calendar, as of JDK 7
• Missing abstractions
• Full of bad surprises
– Unsound design – violates Liskov
– Violat...
Instants
Instants
1379518200000
1379518274000
2013-09-18T15:30Z
2013-09-18T15:31:14Z
2013-09-18T18:30+03:00
2013-09-18T18:31:14+03:...
Civil time
Instants ↔ Civil time
Let’s Practice !
Java 8 Time vs Joda Time
We love .NET too
http://nodatime.org/
Java 8 Time – Recap
• Instants
• Civil time (Days, Months, Weeks)
• Zones and Offsets
• Choose your abstractions well,
and...
Instants
1379518200000
1379518274000
2013-09-18T15:30Z
2013-09-18T18:30+03:00
java.time.Instant
java.time.ZonedDateTime
ja...
Civil time java.time.LocalDateTime
java.time.Period
Q, and, hopefully, A
?
Links
• Java 8 EA https://jdk8.java.net/download.html
– Current version: b106
• Javadocs: http://download.java.net/jdk8/do...
Thank you!
Java Date and Time - Past and Future
Java Date and Time - Past and Future
Java Date and Time - Past and Future
Java Date and Time - Past and Future
Java Date and Time - Past and Future
Java Date and Time - Past and Future
Upcoming SlideShare
Loading in …5
×

Java Date and Time - Past and Future

1,456 views

Published on

Reasoning correctly about dates and times seems easy but is not. Designing a good date/time API is even harder. We will be looking at how Java got it wrong so far, and how things will change with the upcoming JDK 8.

Presentation for the Iasi JUG, 18 September 2013

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,456
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Wed 18 Sep 2013 18:30:00 EEST
  • Java Date and Time - Past and Future

    1. 1. Java Date and Time Past and Future Iulian Dogariu Ness Technologies Iași Java User Group 1379518200000
    2. 2. APIs that make me happy
    3. 3. Timestamp
    4. 4. “System.currentTimeMillis() should be enough for anybody” -- Bill Gates, after seeing the JDK 1.0 Javadocs (well, not really)
    5. 5. java.util.Date
    6. 6. java.util.Calendar
    7. 7. POLA !
    8. 8. java.util.Calendar, as of JDK 7 • Missing abstractions • Full of bad surprises – Unsound design – violates Liskov – Violates POLA – Getter methods with side effects! – Not thread safe – Untestable
    9. 9. Instants
    10. 10. Instants 1379518200000 1379518274000 2013-09-18T15:30Z 2013-09-18T15:31:14Z 2013-09-18T18:30+03:00 2013-09-18T18:31:14+03:00
    11. 11. Civil time
    12. 12. Instants ↔ Civil time
    13. 13. Let’s Practice !
    14. 14. Java 8 Time vs Joda Time
    15. 15. We love .NET too http://nodatime.org/
    16. 16. Java 8 Time – Recap • Instants • Civil time (Days, Months, Weeks) • Zones and Offsets • Choose your abstractions well, and the rest is simple
    17. 17. Instants 1379518200000 1379518274000 2013-09-18T15:30Z 2013-09-18T18:30+03:00 java.time.Instant java.time.ZonedDateTime java.time.OffsetDateTime
    18. 18. Civil time java.time.LocalDateTime java.time.Period
    19. 19. Q, and, hopefully, A ?
    20. 20. Links • Java 8 EA https://jdk8.java.net/download.html – Current version: b106 • Javadocs: http://download.java.net/jdk8/docs/api/ • ISO 8601: http://en.wikipedia.org/wiki/ISO_8601 • Olson TZ aka Zoneinfo – http://www.iana.org/time-zones – http://en.wikipedia.org/wiki/Tz_database • Stephen Colebourne - author of Joda Time
    21. 21. Thank you!

    ×