判断日期是否在当前月份的月初(月中之前)

 1                     String endDate = "2020-11-11";
 2                     DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
 3                     Calendar c = Calendar.getInstance();
 4                     try {
 5                         c.setTime(format.parse(endDate));
 6                     } catch (ParseException e) {
 7                         Logger.error(e.getMessage());
 8                     }
 9                     // 当前月最后一天
10                     int maxDay = c.getActualMaximum(Calendar.DATE);
11                     
12                     c.add(Calendar.DATE, maxDay/2);
13                     int day = c.get(Calendar.DAY_OF_MONTH);
14                     if (day < maxDay && day > maxDay/2) { // 月初
15                         // 取上个月的最后一天
16                         c.add(Calendar.MONTH, -1);
17                         c.set(Calendar.DATE, c.getActualMaximum(Calendar.DATE));
18                         
19                         String format2 = format.format(c.getTime());
20                         enddate = new UFLiteralDate(format2.toString());
21                     } else {
22                         enddate = new UFLiteralDate(endDate.toString());
23                     }

 

posted @ 2020-11-20 09:46  向前爬的蜗牛  阅读(729)  评论(0编辑  收藏  举报