Java examples for java.util:Calendar Compare
Checks whether the specified field in two calendar objects holds the same value.
//package com.java2s; import java.util.Calendar; public class Main { public static void main(String[] argv) throws Exception { Calendar first = Calendar.getInstance(); Calendar second = Calendar.getInstance(); int field = 2; System.out.println(equalFields(first, second, field)); }// w w w . j ava2s.c o m /** * Checks whether the specified field in two calendar objects holds the same value. * * @param first * the first calendar object * @param second * the second calendar object * @param field * the Calendar field to check * @return true if the specified field in two calendar objects holds the same value. */ public static boolean equalFields(Calendar first, Calendar second, int field) { return (first == null || second == null) ? first == second : first .get(field) == second.get(field); } }