For Example
Date to convert is 2020-05-10 01:00:00 Current Date is 2020-05-20 01:00:00
It should show 10 days ago
I'm using Calendar class
Calendar cal = Calendar.getInstance();
For Example
Date to convert is 2020-05-10 01:00:00 Current Date is 2020-05-20 01:00:00
It should show 10 days ago
I'm using Calendar class
Calendar cal = Calendar.getInstance();
Try this:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 10);
System.out.println(DateFormat.format("yyyy-MM-dd hh:mm:ss", calendar).toString());
I'm using it. It will automatically remove 10 days from the current date.
Output: I/System.out: 2020-09-07 12:51:50
You can use
java.time
for this, it is now available to lower API versions in Android due to Android API Desugaring:This outputs