Here you can find the source of getPreviousDate(final Date date)
Parameter | Description |
---|---|
date | The date to get the previous date for. |
public static Date getPreviousDate(final Date date)
//package com.java2s; /**/*from w w w .j a v a 2s . c o m*/ * 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; public class Main { /** * Get the date for the day previous to that specified. * * @param date * The date to get the previous date for. * @return The previous date to the one specified. */ public static Date getPreviousDate(final Date date) { return getOffsetDate(date, -1, Calendar.DATE); } /** * Offset the given date by the specified amount. * @param startDate The date to offset. * @param offsetQuantity The amount to offset. Note that negative numbers will result in the returned date being earlier than the supplied date. * @param offsetQualifier The unit to offset the date by. This should be taken from the Calendar constants. * @return The offset Date. */ public static Date getOffsetDate(Date startDate, int offsetQuantity, int offsetQualifier) { Calendar calendar = Calendar.getInstance(); calendar.setTime(startDate); calendar.add(offsetQualifier, offsetQuantity); return calendar.getTime(); } }