Start and end date of a current month

后端 未结 12 2244
我寻月下人不归
我寻月下人不归 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 03:57

    Simple and Best, Try this One

    Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.MONTH, 0);
                calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
                Date monthFirstDay = calendar.getTime();
                calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
                Date monthLastDay = calendar.getTime();
    
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String startDateStr = df.format(monthFirstDay);
            String endDateStr = df.format(monthLastDay);
    
            Log.e("DateFirstLast",startDateStr+" "+endDateStr);
    

提交回复
热议问题