I'm loading a CSV file and need to parse two strings to localdate. Basically my project is about a Highscore list.
Example format in CSV file: {David,18.01.2019,Easy,00:05:30}
br = new BufferedReader(new FileReader(csvFile)); DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy"); DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("HH:mm:ss"); while ((line = br.readLine()) != null) { String[] highscore = line.split(cvsSplitBy); HighScore highScore = new HighScore( highscore[0], LocalDate.parse(highscore[1], dateFormat), highscore[2], LocalDate.parse(highscore[3], timeFormat)); highScoreList.add(highScore); It throws an exception when it tries to parse 00:05:30.
java.time.format.DateTimeParseException: Text '00:05:30' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {},ISO resolved to 00:05:30 of type java.time.format.Parsed
Now I know this has something to do with the format I previously defined in timeFormat but I still don't see my mistake. I hope you guys can help me!
LocalTimewhen parsing the time column?Durationclass (neitherLocalDatenorLocalTime).