Getting wrong month when using SimpleDateFormat.parse

前端 未结 3 1510
长情又很酷
长情又很酷 2020-11-27 23:59

In my programm there is a very strange problem. Here you can see String birthday and Log to check it:

birthday = String.valueOf(bir         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 00:27

    Use:

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    

    Use MM for month, mm for minutes as stated by documentation...

    If you want to print a Date in a specific format, you should use:

     sdf.format(birthday)
    

    or another SimpleDateFormat if you want to pring it in a different format...

提交回复
热议问题