is Same Month Of Year - Java java.util

Java examples for java.util:Month

Description

is Same Month Of Year

Demo Code

/*/*w w w .j  a v a  2s  .  c  o m*/
 * Copyright 2009 Yodlee, Inc.  All Rights Reserved.  Your use of this code 
 * requires a license from Yodlee.  Any such license to this code is 
 * restricted to evaluation/illustrative purposes only. It is not intended 
 * for use in a production environment, and Yodlee disclaims all warranties 
 * and/or support obligations concerning this code, regardless of the terms 
 * of any other agreements between Yodlee and you."
 */
//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        System.out.println(isSameMonthOfYear(calendar1, calendar2));
    }

    public static boolean isSameMonthOfYear(Calendar calendar1,
            Calendar calendar2) {

        return (getYear(calendar1) == getYear(calendar2))
                && (getMonth(calendar1) == getMonth(calendar2));
    }

    public static int getYear(Calendar calendar) {
        return calendar.get(Calendar.YEAR);
    }

    public static int getMonth(Calendar calendar) {
        return calendar.get(Calendar.MONTH);
    }
}

Related Tutorials