Java Date Before getDateBeforeToday(int num)

Here you can find the source of getDateBeforeToday(int num)

Description

get Date Before Today

License

Open Source License

Declaration

public static String getDateBeforeToday(int num) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final long MILLISECOND_IN_DAY = 1000 * 60 * 60 * 24;

    public static String getDateBeforeToday(int num) {
        long longtimes = System.currentTimeMillis() - num * MILLISECOND_IN_DAY;
        Date date = new Date(longtimes);
        return convertDateToStr(date, "yyyy-MM-dd");
    }//w ww.  j  a  v  a2s  .co m

    public static String convertDateToStr(Date d, String format) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(format);
        String s;
        try {
            s = simpledateformat.format(d).toString();
            return s;
        } catch (Exception e) {
            s = "1900-01-01";
        }
        return s;
    }
}

Related

  1. getDateBeforeNextMonth(Date date, Integer month, Integer day)
  2. getDateBeforeOrAfter(int iDate)
  3. getDateBeforeOrAfterV2(int idx)
  4. getDateBeforeSomeMinutes(int minute, long timestamp)
  5. getDateBeforeTheDay(String day, int num)
  6. getDateBeforTwelveMonth()
  7. getDateTimeAfterOfBeforeHour(Integer AfterOfBeforeHour)
  8. getDayBeforeOrAfter2(Date time, int days)
  9. getDayFormSomeDay(Date date, int n, boolean before)