Get first date of current month in java

前端 未结 9 1759
日久生厌
日久生厌 2020-11-29 05:28

I am trying to get to and from date where ToDate will have previous date and FromDate will have first date of the current month. For January it wou

9条回答
  •  再見小時候
    2020-11-29 06:07

    Works Like a charm!

    public static String  getCurrentMonthFirstDate(){
        Calendar c = Calendar.getInstance();   
        c.set(Calendar.DAY_OF_MONTH, 1);
        DateFormat df = new SimpleDateFormat("MM-dd-yyyy");
        //System.out.println(df.format(c.getTime())); 
        return df.format(c.getTime());
    }
    

    //Correction :output =02-01-2018

提交回复
热议问题