Java tutorial
//package com.java2s; //License from project: LGPL import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { private static final SimpleDateFormat mFormat = new SimpleDateFormat("yyyy-MM-dd"); /** * returns the string representation of the date X days ago * in the appropriate format for the URL * @param _numDaysAgo number of days before the current day * @return string representation of X days ago */ public static String getUrlTimeStringForXDaysAgo(int _numDaysAgo) { GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_MONTH, -1 * _numDaysAgo); return getUrlTimeString(cal); } /** * returns the string representation of the passed GregorianCalendar * in the appropriate format for the URL * @param _cal the calendar to use the date from * @return string representation of the passed date */ public static String getUrlTimeString(GregorianCalendar _gc) { return getUrlTimeString(_gc.getTime()); } public static String getUrlTimeString(Date _d) { return mFormat.format(_d); } }