今天是2014-04-06 – SUNDAY.
开始日期= 2014-04-07
结束日期= 2014-04-13
我想输出为: –
开始日期= 2014-03-31
结束日期= 2014-04-06
// Get calendar set to current date and time Calendar c = GregorianCalendar.getInstance(); System.out.println("Current week = " + Calendar.DAY_OF_WEEK); // Set the calendar to monday of the current week c.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY); System.out.println("Current week = " + Calendar.DAY_OF_WEEK); // Print dates of the current week starting on Monday DateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.getDefault()); String startDate = "",endDate = ""; startDate = df.format(c.getTime()); c.add(Calendar.DATE,6); endDate = df.format(c.getTime()); System.out.println("Start Date = " + startDate); System.out.println("End Date = " + endDate);
解决方法
我相信只需使用:
c.setFirstDayOfWeek(Calendar.MONDAY);
会解决你的问题… 原文链接:https://www.f2er.com/java/121468.html