Compare dates ignoring milliseconds?

前端 未结 10 1316
北海茫月
北海茫月 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条回答
  •  猫巷女王i
    2021-02-08 07:25

    clearMilis(date1).compareTo(clearMilis(date2))
    
    
    /**
     * @param date date
     *
     * @return truncated miliseconds
     */
    @Nonnull
    public static Date clearMillis(final @Nonnull Date date)
    {
        DateTime result = new DateTime(date);
    
        return result.minusMillis(result.getMillisOfSecond()).toDate();
    }
    

提交回复
热议问题