0

The title might sound a bit generic but here are the specifics of the question

  • Why exactly a lot of APIS in Date class deprecated in favor of Calendar ?
  • Why using Calendar is better ? Is is computationally efficient or some other reason ?
  • I currently rely on JodaTime for most of the date manipulations. Does Calendar api does something better or different than JodaTime ?
  • "Does Calendar api does something better than JodaTime". No. JodaTime exists only because the JDK Date/Calendar API are so horrible. Might be better with JDK8 (did not check). – Thilo Sep 16 '14 at 00:56
  • 1
    Related: http://stackoverflow.com/questions/1571265/why-is-the-java-date-api-java-util-date-calendar-such-a-mess – Thilo Sep 16 '14 at 00:57
  • 2
    I recommand you to continue using JodaTime, it's way much better! – JSlain Sep 16 '14 at 00:57
  • @Thilo Java8 date and time objects are immutable – ndrone Sep 16 '14 at 01:04
  • @Thilo Although I agree that old Calendar-API is horrible, there are indeed some things Joda-Time cannot do, for example localized week definitions (no support for US-week), but this is supported by Calendar-stuff (internationalization there is still better). – Meno Hochschild Sep 16 '14 at 05:39

2 Answers2

1

Keep using Joda-Time or use Java 8 - Date and Time API (which is based/inspired on Joda-Time).

Consider java.util.Date and java.util.Calendar as deprecated/obsolete.

Read Why is the Java date API (java.util.Date, .Calendar) such a mess? and Why do we need a new date and time library?

Community
  • 1
  • 1
Ricardo Veguilla
  • 3,107
  • 1
  • 18
  • 17
1

a) Most parts of java.util.Date was deprecated in Java 1.1 in favor of java.util.Calendar because it simply lacked of timezone support.

b) Calendar has much more manipulations than java.util.Date, but for storing and formatting purposes latter one is still the only option. Remember that you cannot directly format a Calendar-object with SimpleDateFormat.

c) On most areas Joda-Time is better, for example immutability. But especially internationalization is better with old Calendar-stuff, for example localized week definition support, for some people this is a showstopper regarding Joda-Time.

d) Keep also in mind that Joda-Time is now rather an old API (for example not using enums). Some internal concepts are effectively deprecated by its own developer in favor of the new date-and-time-library in Java 8 (JSR-310, java-time-package). My prediction, Joda-Time will slowly fade out - also because it is obvious that Stephen Colebourne prefers to invest his resources in Java-8 and an extra external library called Threeten-Extra (which contains some extra calendar systems). Main remaining argument in favor of Joda-Time is still support for mixed date-and-time-periods, some simple interval-support and period formatting support.

Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126