Java Date and Time - Past and Future
Post on 15-Jun-2015
963 Views
Preview:
DESCRIPTION
Transcript
JavaDate and Time
Past and Future
Iulian DogariuNess Technologies
Iași Java User Group1379518200000
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
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:30Z2013-09-18T18:30+03:00
java.time.Instantjava.time.ZonedDateTimejava.time.OffsetDateTime
java.tim
e.Durati
on
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!
top related