Below is the code that I use to access a date in the past, 10 days ago. The result is 20130103, which today is the date. How can I return today's date - 10 days? I will limit myself to using the built-in java date classes, so I can't use Joda time.
package past.date; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class PastDate { public static void main(String args[]){ DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Date myDate = new Date(System.currentTimeMillis()); Date oneDayBefore = new Date(myDate.getTime() - 10); String dateStr = dateFormat.format(oneDayBefore); System.out.println("result is "+dateStr); } }
source share