Here you can find the source of getTargetDay(String day, int beforeOrAfterDays)
public static String getTargetDay(String day, int beforeOrAfterDays)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getTargetDay(String day, int beforeOrAfterDays) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date date = null;/*from ww w .j a v a 2 s . c o m*/ Date targetDate = null; try { date = sdf.parse(day); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DATE, beforeOrAfterDays); targetDate = cal.getTime(); } catch (ParseException e) { e.printStackTrace(); } return sdf.format(targetDate); } public static String getTime() { return getDateTime("HHmmss"); } public static String getDateTime(String format) { java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format); String strDate = sdf.format(new java.util.Date()); return strDate.toString(); } public static String getDateTime() { return getDateTime("yyyyMMddHHmmss"); } }