Snippets

cutiko How to use JodaTime DateComparator

Created by cutiko
DateTime d1 = new DateTime(2014,05,12,7,30,45);
DateTime d2 = new DateTime(2014,05,12,7,30,45);

//get result of comparison
int result = DateTimeComparator.getInstance().compare(d1, d2);
switch (result) {
    case -1:
        System.out.println("d1 is less than d2");
        break;
    case 0:
        System.out.println("d1 is equal to d2");
        break; 
    case 1:
        System.out.println("d1 is greater than d2");
        break;

    default:
        break;
}

Comments (0)