Java Date Compare isInDate(Date date, Date compareDate)

Here you can find the source of isInDate(Date date, Date compareDate)

Description

is In Date

License

Apache License

Declaration

public static boolean isInDate(Date date, Date compareDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
    public static SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");

    public static boolean isInDate(Date date, Date compareDate) {
        if (compareDate.after(getStartDate(date)) && compareDate.before(getFinallyDate(date))) {
            return true;
        } else {/*  w w  w  .  j a va  2  s . c  o m*/
            return false;
        }
    }

    public static Date getStartDate(Date date) {
        String temp = format.format(date);
        temp += " 00:00:00";

        try {
            return format1.parse(temp);
        } catch (Exception e) {
            return null;
        }
    }

    public static Date getFinallyDate(Date date) {
        String temp = format.format(date);
        temp += " 23:59:59";

        try {
            return format1.parse(temp);
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date parse(Long time) {
        if (time == null) {
            return null;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(time);
        return cal.getTime();
    }

    public static String getTime(String pattern) {
        return new SimpleDateFormat(pattern).format(new Date());
    }
}

Related

  1. getCompareDate(String strDate1, String strDate2, String pFormat)
  2. getCompareDateNum(String sDateValue1, String sDateValue2)
  3. getCompareResult(String date1, String date2)
  4. isAfterOrEqual(Date date, Date toCompare)
  5. isBeforeDate(String sCompareDate)
  6. max(Collection datumok)
  7. max(Date a, Date b)
  8. max(final Date a, final Date b)
  9. max(Set dateSet)