Archive for October, 2011

Java is my nightmare

Java is my nightmare

“I will just add a date formatted string for Christmas this year,” I thought.  How hard could that be?  Much later, this code:

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        GregorianCalendar gcdate = new GregorianCalendar(2011, 12, 25);
        java.util.Date date = new Date();
        gcdate.set(GregorianCalendar.ERA, GregorianCalendar.AD);
        Log.d(TAG, "GCdate = "+gcdate.toString());
        Log.d(TAG, "date = "+dateFormat.format(date));
        long millis =  gcdate.getTimeInMillis();
        date = new Date( millis);
        Log.d(TAG, "date now is "+dateFormat.format(date));

Gives these log entries:

GCdate = java.util.GregorianCalendar[time=?,areFieldsSet=false,lenient=true,
date = 3912-01-25 // ?!
date now is 2012-01-25 // What a Terrible Failure.

Obviously, I could just use “2011-12-25” and be done with it, but I will be working with other dates and need to understand why this lunacy. Surely any sane implementation would allow you to set the year, month and date using numbers? How hard can it be to set a Date object to a specific date??

Time and again I have this “how hard could it be?” experience with java ending up being something of a soul destroying experience.

The answer, by the way, appears to be that GregorianCalendar runs from 1-12, but Calendar, from which GregorianCalendar is subclassed, runs from 0-11 for the months.  If lenient is true, then values which are out of bounds are rolled into the following month etc.

Disposable Society (Printers)

Disposable Society (Printers)


I could either pay $500 for a new fuser for my (not so) old (maybe 4 or 5 years) HP printer or I could pay a little less and buy a complete, largely equivalent new laser printer.

Blog Stats

  • 224,556 hits

OSWALD Newsletter

If you would like to receive OSWALD, a weekly open source news digest please send an email to oswald (with the subject "subscribe") at