aspose file tools
The moose likes Java in General and the fly likes Grouse about Calendar, DateFormat, Date Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Grouse about Calendar, DateFormat, Date" Watch "Grouse about Calendar, DateFormat, Date" New topic
Author

Grouse about Calendar, DateFormat, Date

Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Does anyone else find Sun engineers' implementation of the dates classes as counter-intuitive as I do?
I just can't seem to remember anything because it runs so against what one would expect.

Some pet peeves:


1. When Calendar class and DateFormat class were meant to work in tandem, why doesn't the format() method of DateFormat take a Calendar instance as an argument? Why the need use a Date instance as a bridge?

2. Calendar class is full of umpteen utilities (methods & constants). So why not provide a simple method to find the difference between two Calendar dates? Why does every java programmer have to write his/her own utility of converting to milliseconds, finding the difference, dividing by 3600... and so on?

3. Why name the method of converting a Calendar date instance to a Date instance getTime()? Why not getDate()? [I can never ever remember it]. And oh, the getTime() method of Date it totally different, gives you back milliseconds, nothing to do with getTime() of Calendar.

I'm sure they have their own complicated reasons to do it this way, but I just can't figure out why.



"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
1. When Calendar class and DateFormat class were meant to work in tandem, why doesn't the format() method of DateFormat take a Calendar instance as an argument? Why the need use a Date instance as a bridge?


That would be because DateFormat came out in JDK 1.0. Calendar didn't come out until JDK 1.1. Assuming that DateFormat and Calendar were meant to work together seems a bit presumptuous. Since Date has been around since JDK 1.0, it seems more likely that DateFormat was meant to work with Date.

John.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

John,

Thanks. That makes sense. But couldn't they just overload the format() method in new versions to include Calendar as an argument too, specially since it seems like they plan to deprecate the Date class as time goes by?

- Nidhi
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Nidhi:

I suppose, but how hard is it to write this:

John.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Not very! I'm just lazy
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
LOL . I seem to remember Larry Wall quoting laziness as a programming virtue.

John.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Nidhi, you should check out Joda time. I haven't used it myself yet, but a lot of people are recommending it over Java's own date/time system. I've even heard stories of Joda time being incorporated into the Java 7 core API.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Grouse about Calendar, DateFormat, Date
 
Similar Threads
birthdate
Something wrong with GregorianCalendar
Date Calculations - Difference between 2 dates is off
problem with the compareto method in date class
Problem with Calendar().getTime()