Q:

How do I find find first Thursday in a month by using Calendar class in Java?

I found this method here:    
public Date getLastFriday( int month, int year ) {
    Calendar cal = Calendar.getInstance();
    cal.set( year, month + 1, 1 );
    cal.add( Calendar.DAY_OF_MONTH, -(cal.get( Calendar.DAY_OF_WEEK ) % 7 + 1 ));
    return cal.getTime();
} 

I want similar functionality like this:
private Date getFirstThursday(Date now) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(now);
    cal.add(Calendar.DAY_OF_MONTH, ???);
    return cal.getTime();
}

Can anyone help what I should replace? Marked with.

A:

Try this code:
private static Date getFirstThursday(Date now) {
  Calendar cal = Calendar.getInstance();
  cal.setTime(now);
  cal.set(Calendar.WEEK_OF_MONTH, 1);
  cal.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);

  return cal.getTime();
}

