java计算当前月的第几周,及周的起止日期

java计算当前月的第几周,及周的起止日期
 1 public static void printWeeks() {
 2         SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
 3         Calendar calendar = Calendar.getInstance();
 4         calendar.set(Calendar.DATE, 1);
 5         int month = calendar.get(Calendar.MONTH);
 6         int count = 0;
 7         while (calendar.get(Calendar.MONTH) == month) {
 8             if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
 9                 StringBuilder builder = new StringBuilder();
10                 builder.append("week:");
11                 builder.append(++count);
12                 builder.append(" (");
13                 builder.append(format.format(calendar.getTime()));
14                 builder.append(" - ");
15                 calendar.add(Calendar.DATE, 6);
16                 builder.append(format.format(calendar.getTime()));
17                 builder.append(")");
18                 System.out.println(builder.toString());
19             }
20             calendar.add(Calendar.DATE, 1);
21         }
22     }
java计算当前月的第几周,及周的起止日期

 打印结果:

java计算当前月的第几周,及周的起止日期

java计算当前月的第几周,及周的起止日期

上一篇:expdp导出时,输出日志的内容不完整解决方案


下一篇:CentOS7.5上卸载Oracle19c