I have been trying to parse the String I got from the CSV file and convert the column "start" to hour. Here is my code:
public class BeerSong {
private static final String csvFileName = "HourList201403.csv";
public static void main (String[] args) throws IOException, java.text.ParseException {
CSVReader csvReader = new CSVReader(new FileReader(csvFileName));
List<String[]>allLine = csvReader.readAll();
SimpleDateFormat start = new SimpleDateFormat("HH:mm");
Calendar calendar = GregorianCalendar.getInstance();
int startH;
Date startHour;
for (String[] line : allLine) {
startHour=start.parse(line[3]);
calendar.setTime(startHour);
startH = calendar.get(Calendar.HOUR);
System.out.println(line[3]+", "+line[4]);
System.out.println("Work: "+startH);
}
}
}
When I try to run, it outputs an error:
Exception in thread "main" java.text.ParseException: Unparseable date: "Start"
So, what am I doing wrong here and how to fix this ?
The CSV format is like this, it has a lot rows so I put some here:
Person Name, Person ID, Date, Start, End
Scott Scala, 2, 2.3.2014, 6:00, 14:00
Janet Java, 1, 3.3.2014, 9:30, 17:00
Scott Scala, 2, 3.3.2014, 8:15, 16:00
Larry Lolcode, 3, 3.3.2014, 18:00, 19:00