Logo

Programming-Idioms

  • Go
  • 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
import "time"
b := d1.Before(d2)

d1, d2 have type time.Time.
bool b = d1 < d2;

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