getting month name wrong with SimpleDateFormat

前端 未结 2 1487
渐次进展
渐次进展 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");
    
    0 讨论(0)
  • 2021-01-19 05:51

    You are using minute instead of month in your pattern. It should be:

    yyyy-MM-dd HH:mm:ss
    
    0 讨论(0)
提交回复
热议问题