To get the date of the past day you can use the below code. You can pass any number of day for which you want to get date instead of 7, I'm getting date of past 7 days in the below example:
/**
* Get date before past 7 days
*
* @return string
*/
public static String findPast7DaysDate()
{
String sdf=null;
try {
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE,-7);
sdf=new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").format(c.getTime());
return sdf;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Hope this will help you :)
0 Comment(s)