我有一个约会,如何让所有日期落在给定日期属于java的那一周?
example:
if i give today's date then i should get all dates belonging to this week.
12 July 2015 to 18 July 2015
Run Code Online (Sandbox Code Playgroud)
请有人帮助我.
我想知道给定日期的星期日期,我已解释为什么这个问题不重复,请在评论前阅读.
Cod*_*roc 12
您可以尝试以下方式,
Calendar cal = Calendar.getInstance();
//cal.setTime(new Date());//Set specific Date if you want to
for(int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
cal.set(Calendar.DAY_OF_WEEK, i);
System.out.println(cal.getTime());//Returns Date
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT
Sun Jul 12 08:12:38 IST 2015
Mon Jul 13 08:12:38 IST 2015
Tue Jul 14 08:12:38 IST 2015
Wed Jul 15 08:12:38 IST 2015
Thu Jul 16 08:12:38 IST 2015
Fri Jul 17 08:12:38 IST 2015
Sat Jul 18 08:12:38 IST 2015
Run Code Online (Sandbox Code Playgroud)