Start and end date of a current month

后端 未结 12 2246
我寻月下人不归
我寻月下人不归 2020-11-29 03:08

I need the start date and the end date of the current month in Java. When the JSP page is loaded with the current month it should automatically calculate the start and end d

12条回答
  •  孤城傲影
    2020-11-29 04:06

    Date begining, ending;
    Calendar calendar_start =BusinessUnitUtility.getCalendarForNow();
      calendar_start.set(Calendar.DAY_OF_MONTH,calendar_start.getActualMinimum(Calendar.DAY_OF_MONTH));
      begining = calendar_start.getTime();
      String start= DateDifference.dateToString(begining,"dd-MMM-yyyy");//sdf.format(begining);
    
    
       //            for End Date of month
      Calendar calendar_end = BusinessUnitUtility.getCalendarForNow();
      calendar_end.set(Calendar.DAY_OF_MONTH,calendar_end.getActualMaximum(Calendar.DAY_OF_MONTH));
          ending = calendar_end.getTime();
          String end=DateDifference.dateToString(ending,"dd-MMM-yyyy");//or sdf.format(end);
    
    enter code here
    
    
    
    public static Calendar getCalendarForNow() {
            Calendar calendar = GregorianCalendar.getInstance();
            calendar.setTime(new Date());
            return calendar;
        }
    

提交回复
热议问题