String to Date conversion returning wrong value

前端 未结 5 1128
感动是毒
感动是毒 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:26

    One issue I see is:

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

    should be:

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

    DD represents Day in YEAR. Read this for more information on SimpleDateFormat.

提交回复
热议问题