Java Tomorrow isTomorrow(Date date)

Here you can find the source of isTomorrow(Date date)

Description

is Tomorrow

License

Apache License

Declaration

public static boolean isTomorrow(Date date) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final long m_second = 1000;
    public static final long m_minute = m_second * 60;
    public static final long m_hour = m_minute * 60;
    public static final long m_day = m_hour * 24;

    public static boolean isTomorrow(Date date) {
        if (date == null)
            return false;
        if (formatDate(addTime(new Date(), 1, 0, 0, 0)).equals(formatDate(date)))
            return true;
        return false;
    }//from  w  ww  .  j a  v a 2 s  . c  o  m

    /**
      * @param date
      * @return formated date by yyyy-MM-dd
      */
    public static final <T extends Date> String formatDate(T date) {
        if (date == null)
            return null;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return dateFormat.format(date);
    }

    public static String formatDate(int days) {
        return formatDate(addDay(new Date(), days));
    }

    /**
      * @param original
      * @param days
      * @param hours
      * @param minutes
      * @param seconds
      * @param mill
      * @return original+day+hour+minutes+seconds+millseconds
      */
    public static final <T extends Date> T addTime(T original, int days, int hours, int minutes, int seconds) {
        if (original == null)
            return null;
        long newTime = original.getTime() + m_day * days + m_hour * hours + m_minute * minutes + m_second * seconds;
        T another = (T) original.clone();
        another.setTime(newTime);
        return another;
    }

    /**
      * @param date
      * @param pattern: Date format pattern
      * @return
      */
    public static final <T extends Date> String format(T date, String pattern) {
        if (date == null)
            return null;
        try {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            String result = df.format(date);
            return result;
        } catch (Exception e) {
            return null;
        }
    }

    public static final <T extends Date> T addDay(T original, int days) {
        if (original == null)
            return null;
        long newTime = original.getTime() + m_day * days;
        T another = (T) original.clone();
        another.setTime(newTime);
        return another;
    }
}

Related

  1. getTomorrow()
  2. getTomorrow(Date date1)
  3. getTomorrowDate(Date date)
  4. getTomorrowDateAsString()
  5. getTomorrowOnlyDate()
  6. tomorrow()