简体   繁体   中英

Java SimpleDateFormat Unparseable date

I'm having this awkward problem with simple date format. I'm parsing some strings from a file and want to convert them in Date object. Strings are like

"2012-04-19 18:33:10"

so my code is:

SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
sdf.setLenient(false);
Date d1 = sdf.parse("2012-04-19 18:33:10");

which gives me

java.text.ParseException: Unparseable date: "2012-04-19 18:33:10"

Without the

setLenient(false)

the output date is

Sun Jan 01 18:33:10 CET 2012

which is very incorrect.

I really don't understand why.

Any help would be appreciated.

Thanks in advance

尝试:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM