Asked • 05/24/19

Comparing two Calendar objects?

I want to compare two Calendar objects to see if they both contain the same date. I don't care about any value below days.I've implemented this and I can't think about any case where it should fail: private static boolean areEqualDays(Calendar c1, Calendar c2) {  SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");  return (sdf.format(c1.getTime()).equals(sdf.format(c2.getTime()))); }Is this approach correct or should I compare c1 and c2 field by field?

1 Expert Answer

By:

Patrick B. answered • 05/24/19

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.