getting month name wrong with SimpleDateFormat

前端 未结 2 1517
渐次进展
渐次进展 2021-01-19 05:15

I am having problem with this small piece of code

SimpleDateFormat sf = new SimpleDateFormat(\"yyyy-mm-dd HH:mm:ss\");

String str = \"2010-03-13 01:01:22\";         


        
2条回答
  •  渐次进展
    2021-01-19 05:34

    mm stands for minute. You should use MM when parsing month:

    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    

提交回复
热议问题