0

The docs say that Date.UTC() is deprecated and should be replaced with some untrivial spell with Calendar (magic phrase, I mean). A bit more extensive search tells me that the proposed remedy is no better and Calendar is arguably the worst JDK API.

Finally I found joda-time-android.

But what I have not seen is one concise, simple explanation (and not an obscure reference to "internationalization problems"):

1) Why Date is bad,

2) Why Date.UTC() is bad, and

3) Why Calendar & friends are bad.

These classes may have problems for the general case, but probably they are ok for my specific problem?

For example, Date is mutable, it is wrong in the long run, but I myself can live with that right now. Yes, the ranges are crazy, but after I add/subtract 1, will I have other problems?

(What I need right now boils down to an alarm-clock that works across time zones. No dates-without-time or dates-in-documents, leap seconds are irrelevant.)

EDIT Folks, I understand that this question and Should I use Java date and time classes or go with a 3rd party library like Joda Time? are roughly about the same topic, but the questions are different:

1) Android means restricted resources, therefore there is a counter-argument of 100+ classes in the .apk

2) My question is different: the question Why Date/Calendar is bad? means that I want to know what problems will be there if I decide to use these classes. I want a concise explanation of the reasons behind the story with these date/time classes.

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
  • 2
    No, the proposed remedy *is* better. `Calendar` is still a bad API, but using that to create an object based on calendrical values is certainly better than `Date`, and while the API for `Calendar` still uses 0-based months (urgh) at least the *year* is sane... – Jon Skeet Mar 26 '15 at 09:11
  • 1
    I go into some details in http://stackoverflow.com/questions/344380/why-is-january-month-0-in-java-calendar/344400#344400 and http://stackoverflow.com/questions/589870/should-i-use-java-date-and-time-classes-or-go-with-a-3rd-party-library-like-joda/589940#589940 – Jon Skeet Mar 26 '15 at 09:12

0 Answers0