Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #115 Compare dates

Set boolean b to true if date d1 is strictly before date d2 ; false otherwise.

import java.util.Date;
boolean before = (d1.compareTo(d2) == -1);

d1, d2 are of type java.util.Date. variable before will contain true if d1 < d2, false otherwise
bool b = d1 < d2;

New implementation...
< >
programming-idioms.org