3

The Date data structure from java.util is almost being depreciated. Hence, we use to have our very own data structure to represent Date (With year, month and date only. No time information)

SimpleDate

I was wondering is there any equivalent data structure in Joda library?

If my project would like to convert to use Joda, there are some extra work. Because previously my project is using convention in Java Calendar, by having January as 0. In Joda, the January is 1

Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
  • 2
    So what if `Date` get deprecated in Java 7? It's not going to suddenly stop working. – skaffman Dec 11 '10 at 16:19
  • 1
    Given the massive legacy of tooling dependant on Date, it's not going anywhere soon. – GaryF Dec 11 '10 at 16:28
  • @skaffman, Date is almost not usable, as getDate, getMonth, getYear are depreciated. I feel very uncomfortable to use method which is marked as depreciated. – Cheok Yan Cheng Dec 11 '10 at 16:31
  • @Yan Cheng CHEOK: Then don't use those methods. A Date is supposed to represent an instance in time. If you want to break that instance down into its components, then use Calendar. – GaryF Dec 11 '10 at 16:35
  • @GaryF, What the point of having Date to present an instance of time, and you cannot get primitive date/month/year information out form it in a straight forward way? Calendar are having poor performance compared to Joda time. We are currently in the process of migrating. http://sourceforge.net/apps/mediawiki/jstock/index.php?title=NextRelease#Some_offline_study_on_the_performance_of_Calendar_and_Joda_DateTime – Cheok Yan Cheng Dec 11 '10 at 16:38
  • Deprecated methods/classes in JavaSE will never be removed. It just indicates that a better option exists. – skaffman Dec 11 '10 at 16:45
  • I will always avoid using depreciated method. http://stackoverflow.com/questions/2941900/is-it-wrong-to-use-deprecated-methods-or-classes-in-java – Cheok Yan Cheng Dec 11 '10 at 16:57
  • @Yan Cheng CHEOK: You don't always need to get those things individually. In my experience, you generally need to persist dates, display them (DateFormat classes) and compare them. It's not often that I find I need anything else. BTW, I prefer Joda's LocalDate to java.util.Date, but the latter isn't going anywhere. – GaryF Dec 11 '10 at 19:04

2 Answers2

2

Joda uses LocalDate to represent a date without time or timezone information.

Don Roby
  • 40,677
  • 6
  • 91
  • 113
1

Use DateTime#toLocalDate() to obtain the local date part.

LocalDate localDate = dateTime.toLocalDate();

Note that months are nowhere in JodaTime 0-based.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555