Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subtract x amount of days from todays date

Tags:

android

I need to count back 90 days, 120 days and 160 days for a few items. How would I code this? I keep finding java code but that brings up errors when I am developing for android.

I need to take todays date and subtract the x amount of days and have it result be displayed on the screen nothing else. Thanks

like image 959
Chris Odg Avatar asked Jan 04 '12 14:01

Chris Odg


1 Answers

You should use the Calendar class :

//Calendar set to the current date 
Calendar calendar=Calendar.getInstance();
//rollback 90 days
calendar.add(Calendar.DAY_OF_YEAR, -90);
//now the date is 90 days back
Log.i("MyApp","90 days ago:"+calendar.getTime().toString());
like image 97
Ovidiu Latcu Avatar answered Sep 21 '22 06:09

Ovidiu Latcu