此代码的作用是打印当周从星期一到星期五的日期.它工作正常,但我想问别的:如果今天是星期六或星期日,我希望它显示下周.我怎么做?
到目前为止,这是我的工作代码(感谢StackOverflow !!):
// Get calendar set to current date and time
Calendar c = Calendar.getInstance();
// Set the calendar to monday of the current week
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// Print dates of the current week starting on Monday to Friday
DateFormat df = new SimpleDateFormat("EEE dd/MM/yyyy");
for (int i = 0; i <= 4; i++) {
System.out.println(df.format(c.getTime()));
c.add(Calendar.DATE, 1);
}
Run Code Online (Sandbox Code Playgroud)
非常感谢!我真的很感激,因为我一直在寻找解决方案......