Here you can find the source of getDayEnd(final Date date, TimeZone timezone)
Parameter | Description |
---|---|
date | The date to get the day end date for. |
timezone | The timezone that the Date should have. |
public static Date getDayEnd(final Date date, TimeZone timezone)
//package com.java2s; /**/*from w w w . java 2 s. c om*/ * Copyright 2000-2012 TrackMate * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /** The last hour of the day (23). */ private static final int LAST_HOUR_IN_DAY = 23; /** The last minute of the hour (59). */ private static final int LAST_MINUTE_IN_HOUR = 59; /** The last minute of the hour (59). */ private static final int LAST_SECOND_IN_MINUTE = 59; /** The last millisecond of the second (999). */ private static final int LAST_MILLI_IN_SECOND = 999; /** * Get a Date representing the end of the day for the specified date. * * @param date * The date to get the day end date for. * @return The date for the end of the specified day. */ public static Date getDayEnd(final Date date) { return getDayEnd(date, null); } /** * Get a Date representing the end of the day for the specified date. * * @param date * The date to get the day end date for. * @param timezone The timezone that the Date should have. * @return The date for the end of the specified day. */ public static Date getDayEnd(final Date date, TimeZone timezone) { Calendar calendar = Calendar.getInstance(); if (timezone != null) { calendar.setTimeZone(timezone); } calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, LAST_HOUR_IN_DAY); calendar.set(Calendar.MINUTE, LAST_MINUTE_IN_HOUR); calendar.set(Calendar.SECOND, LAST_SECOND_IN_MINUTE); calendar.set(Calendar.MILLISECOND, LAST_MILLI_IN_SECOND); return calendar.getTime(); } }