Java Day Next nextDay(Date date)

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

Description

Returns the day after date.

License

Open Source License

Parameter

Parameter Description
date Date used in calculating next day

Return

Day after date.

Declaration

public static Date nextDay(Date date) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {
    private static Calendar CALENDAR = Calendar.getInstance();

    /**/*from  w w  w .jav  a2  s  .  co  m*/
     * Returns the day after <code>date</code>.
     *
     * @param date Date used in calculating next day
     * @return Day after <code>date</code>.
     */
    public static Date nextDay(Date date) {
        return new Date(addDays(date.getTime(), 1));
    }

    /**
     * Returns the day after <code>date</code>.
     *
     * @param date Date used in calculating next day
     * @return Day after <code>date</code>.
     */
    public static long nextDay(long date) {
        return addDays(date, 1);
    }

    /**
     * Adds <code>amount</code> days to <code>time</code> and returns
     * the resulting time.
     *
     * @param time Base time
     * @param amount Amount of increment.
     *
     * @return the <var>time</var> + <var>amount</var> days
     */
    public static long addDays(long time, int amount) {
        Calendar calendar = CALENDAR;
        synchronized (calendar) {
            calendar.setTimeInMillis(time);
            calendar.add(Calendar.DAY_OF_MONTH, amount);
            return calendar.getTimeInMillis();
        }
    }
}

Related

  1. getNextDayZeroPoint()
  2. nextDay(Date d)
  3. nextDay(Date date)
  4. nextDay(Date date)
  5. nextDay(Date date)
  6. nextDay(Date date)
  7. nextDay(Date then)