Returns true if the two given calendars are dated on the same year. - Java java.util

Java examples for java.util:Year

Description

Returns true if the two given calendars are dated on the same year.

Demo Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar one = Calendar.getInstance();
        Calendar two = Calendar.getInstance();
        System.out.println(sameYear(one, two));
    }//  w  w  w  .  j av a2s . co m

    /**
     * Returns <tt>true</tt> if the two given calendars are dated on the same
     * year.
     * 
     * @param one
     *            The one calendar.
     * @param two
     *            The other calendar.
     * @return True if the two given calendars are dated on the same year.
     */
    public static boolean sameYear(Calendar one, Calendar two) {
        return one.get(Calendar.YEAR) == two.get(Calendar.YEAR);
    }
}

Related Tutorials