Here you can find the source of getDateBeforeToday(int num)
public static String getDateBeforeToday(int num)
//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; } }