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

后端 未结 5 804
小蘑菇
小蘑菇 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:35

    You are creating a Date object, which is a representation of a certain point in the timeline. This means that it will have all the parts necessary to represent it correctly, including minutes and seconds and so on. Because you initialize it from a string containing only a part of the date, the missing data will be defaulted.

    I assume you are then "printing" this Date object, but without actually specifying a format like you did when parsing it. Use the same SimpleDateFormat but call the reverse method, format(Date) as Holger suggested

提交回复
热议问题