DATE_GetFirday - 得到本周的周五

public class GetFriday {
//得到本周的周五
public  Date getFriday(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int rollNum = Calendar.FRIDAY - cal.get(Calendar.DAY_OF_WEEK);
long calInMillis = cal.getTimeInMillis() + rollNum*1000*60*60*24;
cal.setTimeInMillis(calInMillis);
System.out.println(cal.getTime());
return cal.getTime();
}
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
Date date01 = null;
try {
date01 = df.parse("20170624");
} catch (ParseException e) {
e.printStackTrace();
}
new GetFriday().getFriday(date01);
}
}

猜你喜欢

转载自blog.csdn.net/mynah886/article/details/74163901