java如何判断指定日期星期几
创建时间:2017-08-30 投稿人: 陶汶其 浏览次数:284
public static void main(String[] args) throws Throwable {
Date d = DateFormatUtil.convertStrToDate("2017-04-17");
for (int i = 0; i < 100; i++) {
String dstr = DateFormatUtil.convertDateToStr(DateUtil.addDays(d, i));
int xqj = dayForWeek(dstr);
if (Calendar.WEDNESDAY == xqj) {
System.out.println(dstr + "|" + xqj);
}
}
}
public static int dayForWeek(String pTime) throws Throwable {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date tmpDate = format.parse(pTime);
Calendar cal = new GregorianCalendar();
cal.setTime(tmpDate);
return cal.get(Calendar.DAY_OF_WEEK);
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。