我在这里找到了这个方法:
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();
}
我想要类似的功能:
private Date getFirstThursday(Date now) {
Calendar cal = Calendar.getInstance();
cal.setTime(now);
cal.add(Calendar.DAY_OF_MONTH, ???);
return cal.getTime();
}
任何人都可以帮我取代吗?标有。
答案 0 :(得分:0)
试试这段代码:
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();
}