Here you can find the source of sameDay(Date d1, Date d2)
Parameter | Description |
---|---|
d1 | non-null date |
d2 | non-null date |
@SuppressWarnings(value = "deprecated") public static boolean sameDay(Date d1, Date d2)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//from w w w. java 2s .co m * test two dates have the same day * @param d1 non-null date * @param d2 non-null date * @return as above */ @SuppressWarnings(value = "deprecated") public static boolean sameDay(Date d1, Date d2) { if (d1.getYear() != d2.getYear()) return false; if (d1.getMonth() != d2.getMonth()) return false; if (d1.getDay() != d2.getDay()) return false; return true; } public static int getYear(Date date) { GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.getInstance(); long time = date.getTime(); calendar.setTimeInMillis(time); return calendar.get(calendar.YEAR); } /** * @param date Date * @return int month number 0-based */ public static int getMonth(Date date) { GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.getInstance(); long time = date.getTime(); calendar.setTimeInMillis(time); return calendar.get(calendar.MONTH); } }