Should I use Calendar.compareTo() to compare dates?

后端 未结 6 1815
情话喂你
情话喂你 2021-02-07 08:36

Is it a valid way of comparing dates:

Calendar someCalendar1 = Calendar.getInstance(); // current date/time
someCalendar1.add(Calendar.DATE, -14);

Calendar some         


        
6条回答
  •  野的像风
    2021-02-07 09:15

    As one example of why Joda is better, take Daylight Savings Time.

    If you're measuring "one day" as 1000 * 60 * 60 * 24 milliseconds, the Date library - and the Calendar library - both forget that there's one day in the year with 25 hours, and another with 23. You will occasionally screw up date calculations if you rely solely on the Java classes built into the J2SE API.

    Joda is half likely to be the drop-in replacement for GregorianCalendar, Calendar, and Date in a future version of Java.

提交回复
热议问题