Calendar date to yyyy-MM-dd format in java

后端 未结 9 925
别跟我提以往
别跟我提以往 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:59

    I found this code where date is compared in a format to compare with date field in database...may be this might be helpful to you...

    When you convert the string to date using simpledateformat, it is hard to compare with the Date field in mysql databases.

    So convert the java string date in the format using select STR_to_DATE('yourdate','%m/%d/%Y') --> in this format, then you will get the exact date format of mysql date field.

    http://javainfinite.com/java/java-convert-string-to-date-and-compare/

提交回复
热议问题