Parse String date in (yyyy-MM-dd) format

后端 未结 5 782
小蘑菇
小蘑菇 2020-11-30 14:51

I have a string in the form \"2013-09-18\". I want to convert it into a java.util.Date. I am doing this

SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM         


        
5条回答
  •  一整个雨季
    2020-11-30 15:42

    You may need to format the out put as follows.

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date convertedCurrentDate = sdf.parse("2013-09-18");
    String date=sdf.format(convertedCurrentDate );
    System.out.println(date);
    

    Use

    String convertedCurrentDate =sdf.format(sdf.parse("2013-09-18"));
    

    Output:

    2013-09-18
    

提交回复
热议问题