Java Date Compare by Month sameMonth(Date date1, Date date2)

Here you can find the source of sameMonth(Date date1, Date date2)

Description

same Month

License

Open Source License

Declaration

public static boolean sameMonth(Date date1, Date date2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Oobium, Inc.//w ww  .ja va2  s . com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Jeremy Dowdall <jeremy@oobium.com> - initial API and implementation
 ******************************************************************************/

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static boolean sameMonth(Date date1, Date date2) {
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(date1);
        c2.setTime(date2);
        return c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH);
    }
}

Related

  1. isSameMonth(final Date d1, final Date d2)
  2. isSameMonth(final Date date1, final Date date2)
  3. monthsBetween(Date firstDate, Date secondDate)
  4. monthsBetween(final Date von, final Date bis)
  5. sameMonth(Date date1, Date date2)
  6. sameMonth(Date dateOne, Date dateTwo)
  7. sameMonthYear(Date firstDate, Date secondDate)