Question: I'm testing the equality of dates that I create using constants and for some reason the tests are all failing.

```
public static Date date(int year, int month, int date, int hour, int minute) {
    Calendar working = GregorianCalendar.getInstance();
    working.set(year, month, date, hour, minute, 1);
    return working.getTime();
}

```

If I create that with the same year, month, date, hour etc then I expect it to be equal. Except that it inconsistantly isn't. I use this function in two different classes and the objects aren't equal - except only *sometimes*.

What's the issue? The epoch it gives me is occasionally 1 second behind the other and I'm not entirely sure why.

Answer: 
getTime is millisecond precision, you are only setting to second precision. So when you compare the Dates using the `.equals()` method it will return false.

Stop using the abomination of the java date time api and use [jodatime](http://www.joda.org/joda-time/) instead.

```
DateTime dateTime = new DateTime().secOfDay().roundFloorCopy();
dateTime.equals(myOtherDateTimeCreatedSameway);

```

Or if you are just worried about date, not time, use LocalDate.
The old calendar-API is undoubtedly horrible in general but I show a possible solution which suppresses the millisecond part generated in constructor. This will work as long as you don't change the timezone. So sometimes the Calendar-API is underestimated while JodaTime is often overestimated.

```
public static Date date(int year, int month, int date, int hour, int minute) {
    // current time in system timezone
    GregorianCalendar working = new GregorianCalendar();

    // assuming you rather want second set to zero
    working.set(year, month, date, hour, minute, 0); 

    // no millisecond part
    working.set(Calendar.MILLISECOND, 0);
    return working.getTime();
}

```