Here you can find the source of sameMonth(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | a parameter |
date2 | a parameter |
public static boolean sameMonth(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /**//from w w w.j a va2 s. co m * Checks if the two given dates have the same month. * * @param date1 * @param date2 * @return */ public static boolean sameMonth(Date date1, Date date2) { if (date1 == null || date2 == null) { return false; } return getMonth(date1) == getMonth(date2); } /** * Extracts the month value from the given date. Note that the month value is count from zero. * * @param date * @return */ public static int getMonth(Date date) { if (date == null) { return 0; } Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.get(Calendar.MONTH); } }