Convert String to java.util.Date

后端 未结 4 483
猫巷女王i
猫巷女王i 2020-11-27 18:46

I am storing the dates in a SQLite database in this format:

d-MMM-yyyy,HH:mm:ss aaa

When I retrieve the date with that format I am get ever

4条回答
  •  情深已故
    2020-11-27 19:33

    I think your date format does not make sense. There is no 13:00 PM. Remove the "aaa" at the end of your format or turn the HH into hh.

    Nevertheless, this works fine for me:

    String testDate = "29-Apr-2010,13:00:14 PM";
    DateFormat formatter = new SimpleDateFormat("d-MMM-yyyy,HH:mm:ss aaa");
    Date date = formatter.parse(testDate);
    System.out.println(date);
    

    It prints "Thu Apr 29 13:00:14 CEST 2010".

提交回复
热议问题