Compare Date objects with different levels of precision

Posted by brainimus on Stack Overflow See other posts from Stack Overflow or by brainimus
Published on 2009-11-04T00:17:47Z Indexed on 2010/06/07 20:22 UTC
Read the original article Hit count: 238

Filed under:
|

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 ignore milliseconds (or any precision I would like it set to)?

Example of a failing assert that I would like to pass:

Date dateOne = new Date();
dateOne.setTime(61202516585000L);
Date dateTwo = new Date();
dateTwo.setTime(61202516585123L);
assertEquals(dateOne, dateTwo);

© Stack Overflow or respective owner

Related posts about java

Related posts about junit