我正在通过 opencsv 从 csv 文件导入数据以插入 mysql 数据库。opencsv 作为字符串导入,对于数据库中的 1 个字段,我需要将其解析为日期格式:yyyy-MM-dd。但是我收到一个错误。
// This is the string that I have extracted from the csv file
String elem1 = nextLine[0];
// printing out to console I can see the string I wish to convert
System.out.println(elem1); => 2015-08-14
// Below is my code to parse the date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date convertedCurrentDate = sdf.parse(elem1);
String date=sdf.format(convertedCurrentDate );
// printing date to console gives me 2015-08-14
System.out.println(date);
如上所述,将日期打印到控制台给了我 2015-08-14。但是我得到了错误:
java.text.ParseException: Unparseable date: ""
有人可以就我做错了什么给我一些建议吗?
行'java.util.Date convertCurrentDate = sdf.parse(elem1);' 是导致错误的行。
谢谢!