Java Day End isNowBetween(Date start, Date end)

Here you can find the source of isNowBetween(Date start, Date end)

Description

is Now Between

License

Open Source License

Declaration

public static boolean isNowBetween(Date start, Date end) 

Method Source Code

//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();
    }
}

Related

  1. isEqualYMD(Date begindate, Date enddate)
  2. isIncludeDay(Date start, Date end, Date target)
  3. isInRange(Date myDate, Date dateStart, Date dateEnd)
  4. isInWorkDay(Calendar start)
  5. isMoreThenMonth(Date startDate, Date enDate)
  6. isSameDay(Calendar cal1, Calendar cal2)
  7. isSameDay(final Calendar calendar1, final Calendar calendar2)
  8. isTodayWithinPeriod(Date periodStart, Date periodEnd)
  9. isValidSendDate(Date sendDate)