my dog learned polymorphism*
The moose likes Java in General and the fly likes Representing times (was: Date and time in Java ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Representing times (was: Date and time in Java )" Watch "Representing times (was: Date and time in Java )" New topic
Author

Representing times (was: Date and time in Java )

bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
Every now and then similar questions pop up. Dates and times seem such a popular subject.
I wonder which types to use to represent the date and time in my javabean. Together they form a timestamp, however the date is part of my business key and the time is not, therefore I wanted to separate them. Currently both are represented by a Date, but this seems somewhat strange.
Related to this, I have lately heard good things about Joda-time, is this worth using and might this help solving my issue?
[ February 17, 2005: Message edited by: Bart Sawyer ]
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
Lot of methods of the java.util.Date class has been decrepated. Check the apis for GregorianCalendar. It can be used instead of Date class.
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
But it feels wrong to use a java.util.Date to represent a time without a meaningful date
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Bart Sawyer:
I have lately heard good things about Joda-time, is this worth using and might this help solving my issue?
Wow, that looks like a really nice and expressive API. I'd say the only downside is al the code that uses java.util.Date. But for a project that makes heavy use of dates and times, it looks pretty sweet.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Tanveer Rameez:
Lot of methods of the java.util.Date class has been decrepated. Check the apis for GregorianCalendar. It can be used instead of Date class.

I would venture to say that the GregorianCalendar and Date classes are NOT completely interchangeable. I think deprecating the Date API was an effort to make Date immutable, somewhat like String is. In fact, I've seen the comparison drawn between String and StringBuffer. In many respects Calendar is to Date as StringBuffer is to String.

Besides this still wouldn't solve the OP's problem since Calendar (or its subclasses, like GregorianCalendar) still store the time AND date together as a single entity.

Layne


Java API Documentation
The Java Tutorial
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
Originally posted by Layne Lund:


Besides this still wouldn't solve the OP's problem since Calendar (or its subclasses, like GregorianCalendar) still store the time AND date together as a single entity.


Indeed, using times without a date does not seem very popular.
 
 
subject: Representing times (was: Date and time in Java )