String to Date conversion returning wrong value

前端 未结 5 1129
感动是毒
感动是毒 2021-01-21 03:49

I am trying to convert a String into Date... But the return value is wrong.

String startDate = \"2013-07-24\";
Date date = new Date();
try{         
    DateForm         


        
5条回答
  •  鱼传尺愫
    2021-01-21 04:23

    Day of the month is made using lowercase 'd', and you're using it uppercase...

    Change it to:

    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    

    at it will work

提交回复
热议问题