Inconsistent date parsing using SimpleDateFormat

后端 未结 4 1119
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 20:14

I\'m really scratching my head on this one. I\'ve been using SimpleDateFormats with no troubles for a while, but now, using a SimpleDateFormat to parse dates is

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 20:51

    I think you want to use the HH format, rather than 'hh' so that you are using hours between 00-23. 'hh' takes the format in 12 hour increments, and so it assumes it is in the AM.

    So this

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse("2009-08-19 12:00:00");
    System.out.print(date.toString());
    

    Should print out

    Wed Aug 19 12:00:00 EDT 2009

提交回复
热议问题