Chapter 4

Working with Dates and Times

IN THIS CHAPTER

check Understanding human and computer dates and times

check Using java.time classes to represent dates and times

check Comparing dates and times

check Performing calculations with dates and times

check Formatting dates and times

Does anybody really know what time it is? Does anybody really care about time?

So mused Robert Lamm of The Chicago Transit Authority (later known as simply Chicago) in 1969.

I’m not sure who cared much about time in 1969, but I do know that the people who designed the original version of Java in 1995 didn’t care much about it, at least as evidenced by the weak classes they provided for working with times and dates in the Java.util package. Java programmers have long struggled with simple calculations involving dates and times, such as determining what the date will be 45 days from today or calculating the number of days between two given dates.

Java finally got with the times with the release of Java 8, which introduced an entirely ...

Get Java All-in-One For Dummies, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.