Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Representing times (was: Date and time in Java )

 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it feels wrong to use a java.util.Date to represent a time without a meaningful date
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic