0

Below is my code snippet and it is failing in my local but works in other DEV's machine, can someone give pointers on what am I missing?

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss a z");
ZonedDateTime releaseDate = ZonedDateTime
                .parse("2021-03-31 10:15:30 AM +05:30", formatter);

Exception

java.time.format.DateTimeParseException: Text '2021-03-31 10:15:30 AM +05:30' could not be parsed at index 20

    at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
    at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)

1 Answers1

0

I note two problems with your pattern:

  • You include HH (24-hour hour) and a (AM/PM). You probably want hh.

  • You use z (time-zone name) but then show +05:30. Perhaps you want either Z or X.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • I tried this formats and not helping "yyyy-MM-dd hh:mm:ss a Z" "yyyy-MM-dd hh:mm:ss X" – bharath sanjai Jun 15 '21 at 05:29
  • 1
    While both points denote real problems, none of them is the source of the exception. There are (at least) three problems with the code … – Ole V.V. Jun 15 '21 at 17:11
  • @OleV.V. any thoughts on what is going wrong here ? – bharath sanjai Jun 16 '21 at 14:22
  • Yes, @bharathsanjai, it’s a locale problem, Just as in the linked original question. You can find your answer there. If you read it and don’t understand it, or don’t understand how it applies to your situation, please revert, and we will guide you further. – Ole V.V. Jun 16 '21 at 14:29