Comparing two Calendar objects

前端 未结 6 963
死守一世寂寞
死守一世寂寞 2020-12-16 10:21

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

6条回答
  •  隐瞒了意图╮
    2020-12-16 10:25

    To compare two dates with respect to a specific field, first set all fields below that one to the lowest value (which is 0 or 1 depending on the field) using Calendar.set(int field, int value) and then compare. To compare differing in days between cal1 and cal2, you will set MINUTE, SECOND and MILLISECOND on both objects to 0 before calling cal1.compare(cal2).

提交回复
热议问题