Java Day End endOfDay(Date inDate, TimeZone timeZone)

Here you can find the source of endOfDay(Date inDate, TimeZone timeZone)

Description

Calculate the date time at the end of the day (one millisecond before midnight) for the given date.

License

Open Source License

Parameter

Parameter Description
inDate The given date.

Return

The Date at the end of the day.

Declaration

public static Date endOfDay(Date inDate, TimeZone timeZone) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    /**//from ww w  .jav a 2 s . co m
     * Calculate the date time at the end of the day (one millisecond before midnight)
     * for the given date.
     * 
     * @param inDate The given date.
     * @return The Date at the end of the day.
     */
    public static Date endOfDay(Date inDate, TimeZone timeZone) {
        Calendar inCalendar = new GregorianCalendar();
        inCalendar.setTimeZone(timeZone);
        inCalendar.setTime(inDate);
        Calendar nextDay = new GregorianCalendar(inCalendar.get(Calendar.YEAR), inCalendar.get(Calendar.MONTH),
                inCalendar.get(Calendar.DAY_OF_MONTH) + 1);
        nextDay.setTimeZone(timeZone);
        return new Date(nextDay.getTime().getTime());
    }
}

Related

  1. endOfDay(Date date)
  2. endOfDay(Date date)
  3. endOfDay(Date date)
  4. endOfDay(Date dateInst)
  5. endOfDay(Date dt)
  6. endOfDay(Date value)
  7. endOfDay(final Date date)
  8. endOfDay(final Date date)
  9. endOfDayDate(Date date)