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 really)
java.util.Date
java.util.Calendar
POLA !
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
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:00
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 the rest is simple
Instants
1379518200000
1379518274000
2013-09-18T15:30Z
2013-09-18T18:30+03:00
java.time.Instant
java.time.ZonedDateTime
java.time.OffsetDateTime
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/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
Thank you!

Java Date and Time - Past and Future

Editor's Notes

  • #2 Wed 18 Sep 2013 18:30:00 EEST