In my CSV file, I have a column whereby I enter
2024-05-05 08:15:00
If I enter that into the CSV file
in Notepad, the value of str is
2024-05-05 08:15:00
, and the second condition is met:
However, if I enter
2024-05-05 08:15:00
into the CSV file
in Excel, the value of str is
5/5/2024 8:15
, and the thrid condition an't be met, because the seconds are lobbed off by the time it gets from the Excel CSV to
Java and throws a java.text.ParseException:
If edited and saved by Excel: 5/5/2024 8:15
java.text.ParseException: Unparseable date: "5/5/2024 8:15"
at java.base/java.text.DateFormat.parse(DateFormat.java:396)
at com.dandylabs.FeedbackBannedIPBeanPopulator.populateBean(FeedbackBannedIPBeanPopulator.java:104)
at com.dandylabs.FeedbackBannedIPUpdater.readCSV(FeedbackBannedIPUpdater.java:282)
at com.dandylabs.FeedbackBannedIPUpdater.perform(FeedbackBannedIPUpdater.java:264)
at com.dandylabs.FeedbackBannedIPUpdater.main(FeedbackBannedIPUpdater.java:307)
I don't know how to fix this, considering users will be editing their CSV files by either Excel or Notepad, depending on who they are, etc. I need for the expire date to be consistently formatted in such a way as to retain seconds every single time, but if they edit in Excel, the seconds are lost by the time Java gets a hold of it.
Any ideas? I am open (in this particular project) to external libraries if need be, e.g. Apache POI, etc.
Thanks