Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Calendar, how can i discover relative date? [duplicate]

Tags:

java

calendar

Possible Duplicate:
How to get date of last Friday from specified date?

Using java.util.Calendar (or any other library), is there a way i can find out what the Date of what Month of what Year was "Friday 2 weeks ago"?

Please advise

like image 296
James Raitsev Avatar asked Feb 04 '26 14:02

James Raitsev


1 Answers

Try this way:

Calendar vCal = Calendar.getInstance();
vCal.add(Calendar.WEEK_OF_YEAR, -2); //two weeks ago
vCal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); //friday

int vDay = vCal.get(Calendar.DAY_OF_MONTH); //day
int vMonth = vCal.get(Calendar.MONTH); //month
int vYear = vCal.get(Calendar.YEAR); //year

Date d = vCal.getTime(); //full date

Good luck.

like image 145
Andrei Petrenko Avatar answered Feb 06 '26 05:02

Andrei Petrenko