Calendar cNow = Calendar.getInstance();
Date dNow = cNow.getTime();
cNow.add(Calendar.DATE, Day);
Date beforeDate = cNow.getTime();
SimpleDateFormat format =
new SimpleDateFormat("MMM dd, yyyy hh:mm:ss
a");
String dateNow = format.format(dNow);
String dayBefore = format.format(beforeDate);
System.out.println(dateNow);
System.out.println(dayBefore);
________________________________________________
Day is a integer value either in + or - base on requirement
- Day will give you past date
+ Day will give you future date
No comments:
Post a Comment