Compare Date objects with different levels of precision

前端 未结 19 2013
日久生厌
日久生厌 2020-12-08 13:01

I have a JUnit test that fails because the milliseconds are different. In this case I don\'t care about the milliseconds. How can I change the precision of the assert to i

19条回答
  •  死守一世寂寞
    2020-12-08 13:30

    Here is a utility function that did the job for me.

        private boolean isEqual(Date d1, Date d2){
            return d1.toLocalDate().equals(d2.toLocalDate());
        }
    
    

提交回复
热议问题