Here you can find the source of compareDate(Date d1, Date d2)
Parameter | Description |
---|---|
d1 | a parameter |
d2 | a parameter |
public static int compareDate(Date d1, Date d2)
//package com.java2s; /*// w w w . j ava 2 s. co m * Copyright (C) 2010 Viettel Telecom. All rights reserved. * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.util.Calendar; import java.util.Date; public class Main { /** * tra ve 1 neu date1 sau date2 * * @param d1 * @param d2 * @return */ public static int compareDate(Date d1, Date d2) { int result = 0; Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(d1); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); cal2.setTime(d2); cal2.set(Calendar.HOUR_OF_DAY, 0); cal2.set(Calendar.MINUTE, 0); cal2.set(Calendar.SECOND, 0); cal2.set(Calendar.MILLISECOND, 0); if (cal1.after(cal2)) { result = 1; } else if (cal1.before(cal2)) { result = -1; } return result; } }