Java Day of isIn(int reserveDayCount, String dateString)

Here you can find the source of isIn(int reserveDayCount, String dateString)

Description

is In

License

Apache License

Declaration

public static boolean isIn(int reserveDayCount, String dateString) 

Method Source Code


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

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

public class Main {
    public static boolean isIn(int reserveDayCount, String dateString) {
        Date date = date(dateString);
        int interval = interval(date, new Date());
        if (interval < 0) {
            return reserveDayCount > Math.abs(interval);
        }/*from w w w . j  ava 2 s .  com*/
        return false;
    }

    public static Date date(String date, String format) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        try {
            return dateFormat.parse(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date date(String date) {
        return date(date, "yyyy.MM.dd");
    }

    public static int interval(Date dateOne, Date dateTwo) {
        Calendar calOne = Calendar.getInstance();
        calOne.setTime(dateOne);
        int dayOne = calOne.get(Calendar.DAY_OF_YEAR);

        Calendar calTwo = Calendar.getInstance();
        calTwo.setTime(dateTwo);
        int dayTwo = calTwo.get(Calendar.DAY_OF_YEAR);
        return dayOne - dayTwo;
    }
}

Related

  1. getYYYY_MM_DD(int offsetDays)
  2. isBirthdayPartAvail(String number)
  3. isDiffIsBiggerThanMin(Date lastLogIn, Date now, Long daysL)
  4. isEndOfDay(GregorianCalendar cal1)
  5. isHoliday(Date date, String[] excludes, String[] includes)
  6. isInAllDayFormat(String date)
  7. isNowDay(String d)
  8. isSomeDay(String date)
  9. lastDays(int count)