Java Date Compare compareDateTimeNull(Date d1, Date d2)

Here you can find the source of compareDateTimeNull(Date d1, Date d2)

Description

compare Date Time Null

License

Open Source License

Declaration

public static int compareDateTimeNull(Date d1, Date d2) 

Method Source Code

//package com.java2s;
/*/*from  www  .  j  a va 2  s  .co  m*/
 * Copyright (C) 2010 dungnv. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static int compareDateTimeNull(Date d1, Date d2) {
        if (d1 == null && d2 == null) {
            return 0;
        }
        if (d1 == null) {
            return -1;
        }
        if (d2 == null) {
            return 1;
        }
        int result = 0;
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal1.setTime(d1);
        cal2.setTime(d2);
        if (cal1.after(cal2)) {
            result = 1;
        } else if (cal1.before(cal2)) {
            result = -1;
        }
        return result;
    }
}

Related

  1. compareDates(Date date1, Date date2)
  2. compareDates(final Date dateA, final Date dateB)
  3. compareDates(final String format, final Date date1, final Date date2)
  4. compareDateSequence(String startDate, String endDate)
  5. compareDatesOnly(long date1, long date2)
  6. compareDay(Date date, Date anotherDate)
  7. compareDay(Date date1, int compday)
  8. compareDays(final Date date1, final Date date2)
  9. compareFileDates(final Date date1, final Date date2)