I have to fetch date of last Thursday of month of any year but the problem I'm facing is that for the month of dec'15
last thursday is 31-dec-2015
but I'm getting 24-dec-2015
for the following code:
Date getLastThursday(def month, def year ) {
Calendar cal = Calendar.getInstance();
cal.set( year, month,1 )
cal.add( Calendar.DAY_OF_MONTH, -(cal.get(Calendar.DAY_OF_WEEK )%7+2) );
return cal.getTime();
}
And also explain me how this line of code internally works?
cal.add(Calendar.DAY_OF_MONTH, -(cal.get(Calendar.DAY_OF_WEEK )%7+2))