获取下周一至周三的时间
public class Demo {
public static void main(String[] args) {
// TODO Auto-generated method stub
// 日期格式转换
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 当前日期
Calendar instance = Calendar.getInstance();
// 调整到下周
instance.add(Calendar.WEDNESDAY, 1);
// 调整到下周1
instance.set(Calendar.DAY_OF_WEEK, -2);
//循环打印
for (int i = 1; i <= 3; i++) {
System.out.println( "星期" + i + ":" +sdf.format(instance.getTime()));
instance.add(Calendar.DAY_OF_WEEK, 1);
}
System.out.println(sdf.format(getStartTime()));
System.out.println(sdf.format(getEndTime()));
private static Date getStartTime() {
Calendar weekdayStart = Calendar.getInstance();
weekdayStart.set(Calendar.HOUR, 0);
weekdayStart.set(Calendar.MINUTE, 0);
weekdayStart.set(Calendar.SECOND, 0);
weekdayStart.set(Calendar.MILLISECOND, 0);
return weekdayStart.getStartTime();
}
private static Date getEndTime() {
Calendar weekdayEnd = Calendar.getInstance();
weekdayEnd.set(Calendar.HOUR, 23);
weekdayEnd.set(Calendar.MINUTE, 59);
weekdayEnd.set(Calendar.SECOND, 59);
weekdayEnd.set(Calendar.MILLISECOND, 999);
return weekdayEnd.getTime();
}
}
}