Here you can find the source of getDiffDateTime(int diff)
public static final Date getDiffDateTime(int diff)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static final String dtSimple = "yyyy-MM-dd"; public static final Date getDiffDateTime(int diff) { Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DATE, diff); return c.getTime(); }/*from w w w . ja va 2 s . co m*/ public static final String getDiffDateTime(int diff, int hours) { Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DATE, diff); c.add(Calendar.HOUR, hours); return dtSimpleFormat(c.getTime()); } /** * yyyy-MM-dd * * @param date * * @return */ public static final String dtSimpleFormat(Date date) { if (date == null) { return ""; } return getFormat(dtSimple).format(date); } private static final DateFormat getFormat(String format) { return new SimpleDateFormat(format); } }