Java Today beforeToday(int days)

Here you can find the source of beforeToday(int days)

Description

before Today

License

Apache License

Declaration

public static Date beforeToday(int days) 

Method Source Code


//package com.java2s;
/*/* ww  w  .  j a  va2s . c  o m*/
 * Copyright 2002-2015 the original author or authors.
 *
 * 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.GregorianCalendar;

public class Main {
    public static Date beforeToday(int days) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(todayMiddleNight());
        calendar.add(Calendar.DATE, -days);
        return calendar.getTime();
    }

    public static Date todayMiddleNight() {

        GregorianCalendar now = new GregorianCalendar();
        now.set(Calendar.HOUR_OF_DAY, 23);
        now.set(Calendar.MINUTE, 59);
        now.set(Calendar.SECOND, 59);
        now.set(Calendar.MILLISECOND, 999);

        return now.getTime();
    }
}

Related

  1. afterToday(String date)
  2. converTimeToDayStartEnd(long time, long[] out)
  3. createTodayDirectory(File destDir)
  4. createTodayDirectory(File destDir, String inputFileName)
  5. createTodayPrefixedDirectory(final String prefix, final File parent)