Compare Date objects with different levels of precision

前端 未结 19 2060
日久生厌
日久生厌 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:12

    Yet another workaround, I'd do it like this:

    assertTrue("Dates aren't close enough to each other!", (date2.getTime() - date1.getTime()) < 1000);
    

提交回复
热议问题