Here you can find the source of isNow(Calendar cal, Locale locale, boolean minuteCheck)
public static boolean isNow(Calendar cal, Locale locale, boolean minuteCheck)
//package com.java2s; /******************************************************************************* * Copyright (c) Emil Crumhorn - Hexapixel.com - emil.crumhorn@gmail.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:/* w w w . j a v a2s .co m*/ * emil.crumhorn@gmail.com - initial API and implementation *******************************************************************************/ import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main { private static int _todayYear; private static int _todayYearDate; private static Locale _locale; public static boolean isNow(Calendar cal, Locale locale, boolean minuteCheck) { if (isToday(cal)) { Calendar today = Calendar.getInstance(locale); if (today.get(Calendar.HOUR_OF_DAY) == cal.get(Calendar.HOUR_OF_DAY)) { if (!minuteCheck) { return true; } if (today.get(Calendar.MINUTE) == cal.get(Calendar.MINUTE)) { return true; } } } return false; } public static boolean isToday(Date date) { Calendar cal = Calendar.getInstance(_locale); cal.setTime(date); return isToday(cal); } /** * Remember to ensure the correct locale is set on the calendar before using this method. * * @param cal Calendar to check * @return true if calendar matches todays date */ public static boolean isToday(Calendar cal) { return (cal.get(Calendar.YEAR) == _todayYear && cal.get(Calendar.DAY_OF_YEAR) == _todayYearDate); } }