String to Date conversion returning wrong value

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

    Replace DD with dd to match the date.

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

    As per the SimpledateFormat documentation

    D Day in year

    d Day in month

提交回复
热议问题