Chapter 6. Dates and Times

Introduction

Yes, Java is Y2K safe. That was the first date-related question people asked before 2,000 AD rolled around, so I’ll answer it up front. The difficulties of date handling in Java arise not from Y2K issues but from Y1970 issues.

When Java was devised in the early 1990s, there was already considerable awareness in the computing industry of the impending problems with some old code. In fairness to practitioners of the 1970s and 1980s, I must add that not all of us ignored the Y2K issue. I read a key early warning sounded around 1974 in Datamation or JACM, and many of my colleagues from that time forward (myself included) paid close attention to issues of date survivability, as did the developers of the Java API.

In the earliest releases of Java, there was a class called Date designed for representing and operating upon dates. Its problems were that it was Anglocentric -- like much of Java 1.0 -- and that its dates began with the Unix time epoch: January 1, 1970. The year is an integer whose minimum value 70 is treated as 1970, so 99 is 1999, 100 is 2000, and so on. Consequently, there is no general Y2K problem with Java. The problem remains that those of us ancient enough to have been born before that venerable year of 1970 in the history of computing -- the time when Unix was invented -- found ourselves unable to represent our birth dates, and this made us grumpy and irritable.

The Anglocentricity and 1970-centricity could have been vanquished with ...

Get Java Cookbook 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.