Here you can find the source of isNowBetween(Date start, Date end)
public static boolean isNowBetween(Date start, Date end)
//package com.java2s; /****************************************************************************** * @File name : DateUtil.java//from ww w . j a va 2s. c o m * * @Package : com.envision.envservice.common.util * * @Author : xuyang.li * * @Date : 2015?10?27? ????5:09:25 * * @Description : ????? * * @Copyright Notice: * Copyright (c) 2015 Envision, Inc. All Rights Reserved. * This software is published under the terms of the Envision Software * License version 1.0, a copy of which has been included with this * distribution in the LICENSE.txt file. * * * ---------------------------------------------------------------------------- * Date Who Version Comments * 2015?10?27? ????5:09:25 xuyang.li 1.0 Initial Version *****************************************************************************/ import java.util.Calendar; import java.util.Date; public class Main { public static boolean isNowBetween(Date start, Date end) { return isBetween(new Date(), todayStartTime(), todayEndTime()); } public static boolean isBetween(Date date, Date start, Date end) { return start.before(date) && end.after(date); } public static Date todayStartTime() { Calendar todayStart = Calendar.getInstance(); todayStart.set(Calendar.HOUR_OF_DAY, 0); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); todayStart.set(Calendar.MILLISECOND, 0); return todayStart.getTime(); } public static Date todayEndTime() { Calendar calendar = Calendar.getInstance(); Date todayStartTime = todayStartTime(); calendar.setTime(todayStartTime); calendar.add(Calendar.DATE, 1); calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } }