private String previouDate(int days) {
String current_date = "", previous_date = ""; Calendar c = Calendar.getInstance(); //System.out.println("Current time => " + c.getTime());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //define your formate for date
current_date = df.format(c.getTime()); previous_date = getCalculatedDate("yyyy-MM-dd", -days); return previous_date; }
private static String getCalculatedDate(String dateFormat, int days) { Calendar cal = Calendar.getInstance(); SimpleDateFormat s = new SimpleDateFormat(dateFormat); cal.add(Calendar.DAY_OF_YEAR, days); return s.format(new Date(cal.getTimeInMillis())); }
No comments:
Post a Comment