简体   繁体   中英

How to convert String date to java.util.Date?

I have a date as a String format like this -

String testDate = "2014-11-5T19:11:27";

Now I need to convert above String date to java.util.Date format. I was trying below code but it is not able to recognize T in it.

String testDate = "2014-11-5T19:11:27";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss");
Date date = formatter.parse(testDate);
System.out.println(date);

T必须用引号引起来,因为它不用于匹配DateFormat模式中的日期元素

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'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