0

i am trying to read CSV file .In CSV file expiry date column is "23-Feb-23"

but when it is read using buffered reader or any method it is read as "23/FEB/23" . And when i tried to parse it it's not at all possible and is giving

Caused by: java.time.format.DateTimeParseException: Text '23/FEB/23' could not be parsed at index 3

below is code i used:

    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MMM-yy");               
             String exp = record.get("expiry");                   
                LocalDate expiry = null;
                if (null != exp && !"".equals(exp)) {
                    expiry = LocalDate.parse(exp, dateTimeFormatter);
                }

i also tried pattern dd/MMM/yy and that also didn't worked.

spa
  • 329
  • 1
  • 3
  • 15
  • I hate [Yoda conditions](https://en.wikipedia.org/wiki/Yoda_conditions). – Ole V.V. Feb 15 '23 at 19:52
  • I find it hard to believe that text with hyphens is being read by Java as slash characters. Provide an [MCVE](https://stackoverflow.com/help/mcve). – Basil Bourque Feb 15 '23 at 21:19
  • 2
    By the way, more readable syntax: `if ( Objects.nonNull( exp ) && ! exp.isBlank() ) {…}`. Better yet would be validating arguments at the top of the method, before any logic. – Basil Bourque Feb 15 '23 at 21:23
  • Tip: When communicating date-time values textually, use only standard [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) formats. – Basil Bourque Feb 15 '23 at 21:27

0 Answers0