Here you can find the source of isSameMonth(final Date d1, final Date d2)
Parameter | Description |
---|---|
d1 | a date |
d2 | the other date |
public static boolean isSameMonth(final Date d1, final Date d2)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.util.Calendar; import java.util.Date; public class Main { /**//ww w .j ava 2 s.co m * @param d1 a date * @param d2 the other date * @return True if the dates represent the same month (year, month) independent of the days, hours, minutes etc. */ public static boolean isSameMonth(final Date d1, final Date d2) { Calendar c1 = Calendar.getInstance(); c1.setTime(d1); Calendar c2 = Calendar.getInstance(); c2.setTime(d2); return c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH); } }