Calendar date to yyyy-MM-dd format in java

后端 未结 9 911
别跟我提以往
别跟我提以往 2020-11-22 06:16

How to convert calendar date to yyyy-MM-dd format.

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
Date date = cal.getTime();          


        
9条回答
  •  一向
    一向 (楼主)
    2020-11-22 06:49

    java.util.Date object can't represent date in custom format instead you've to use SimpleDateFormat.format method that returns string.

    String myString=format1.format(date);
    

提交回复
热议问题