Compare dates ignoring milliseconds?

前端 未结 10 1280
北海茫月
北海茫月 2021-02-08 06:36

Is there a way to compare two calendar objects, but ignore milliseconds?

I have written a test case that compared two calendar objects, but there is a p

10条回答
  •  借酒劲吻你
    2021-02-08 07:16

    One option is to call Calendar.set(Calendar.MILLISECOND, 0) to clear the milliseconds. Another is call getTimeInMillis() to get the time in milliseconds for both calendars. You could then divide these by 1000 before comparing to remove the milliseconds.

提交回复
热议问题