java 判斷兩個日期是否爲同一天

public static boolean isSameDate(Date d1 ,Date d2){
    if (null == d1 || null == d2)
        return false;
    
    if(Math.abs( d1.getTime() - d2.getTime() ) > 3600000*24)
        return false;
    
    Calendar c1 = Calendar.getInstance();
    c1.setTime(d1);
    Calendar c2 = Calendar.getInstance();
    c1.setTime(d2);
    if(c1.get(Calendar.DAY_OF_MONTH) != c2.get(Calendar.DAY_OF_MONTH))
        return false;
    
    return true;
}
相關文章
相關標籤/搜索