-1

When I run below code in the server, I get period after month.

DateTimeFormatter.ofPattern("dd MMM yyyy").format(LocalDate.parse("2023-04-01"))

01 Apr. 2023

There is a period after month.

screenshot

But, same code when I run in java main method, it produces expected output.

DateTimeFormatter.ofPattern("dd MMM yyyy").format(LocalDate.parse("2023-04-01"))

01 Apr 2023

Any reason why the first operation produces period?

Is dateTimeFormatter depends on Locale?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
jBOSS
  • 9
  • 2
  • https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/time/format/DateTimeFormatter.html – kleopatra Apr 01 '23 at 03:57
  • You are correct, it is a locale difference. Perhaps `Apr.` with a dot is German or something and `Apr` without the dot is English or something else. Specify the locale you want, for example `DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.ENGLISH)`. – Ole V.V. Apr 01 '23 at 04:39
  • 1
    Always search Stack Overflow thoroughly before posting. – Basil Bourque Apr 01 '23 at 05:46
  • @BasilBourque This is related to https://bugs.openjdk.java.net/browse/JDK-8211750 . – jBOSS Apr 04 '23 at 01:34

1 Answers1

1

Its depends on Locale.

it produces correct results when I use Locale.US

LocalDate.parse("2023-01-01").format(DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.US))

jBOSS
  • 9
  • 2