From 7e8f8d115f5b262adf2988b4843e7d0a16dd4d50 Mon Sep 17 00:00:00 2001 From: Kah Goh Date: Wed, 18 Feb 2026 19:40:11 +0800 Subject: [PATCH] Mention locales in DateTime concept This updates the date time concept to mention different Locales can be used with the DateTimeFormatter. Locales is needed to solve the corresponding Booking for Beauty exercise, so it would be helpful for students to be aware of this. Resolves #3088 --- concepts/datetime/.meta/config.json | 8 ++++++-- concepts/datetime/about.md | 11 +++++++++++ concepts/datetime/introduction.md | 10 ++++++++++ .../booking-up-for-beauty/.docs/introduction.md | 10 ++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/concepts/datetime/.meta/config.json b/concepts/datetime/.meta/config.json index f68620354..e6bd977c0 100644 --- a/concepts/datetime/.meta/config.json +++ b/concepts/datetime/.meta/config.json @@ -1,5 +1,9 @@ { "blurb": "There are several classes in Java to work with dates and time.", - "authors": ["sanderploegsma"], - "contributors": [] + "authors": [ + "sanderploegsma" + ], + "contributors": [ + "kahgoh" + ] } diff --git a/concepts/datetime/about.md b/concepts/datetime/about.md index 8ab1fbad6..ebeb1b3a3 100644 --- a/concepts/datetime/about.md +++ b/concepts/datetime/about.md @@ -118,7 +118,18 @@ printer.format(date); // => "December 3, 2007" ``` +A [locale][locale] can also be specified when creating the custom format to format and parse for different regions: + +```java +DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.FRENCH).format(date); +// => décembre 3, 2007 + +DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.of("pt")).format(date); +// => dezembro 3, 2007 +``` + [iso-8601]: https://en.wikipedia.org/wiki/ISO_8601 [localdate-docs]: https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html [localdatetime-docs]: https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html +[locale]: https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html [datetimeformatter-docs]: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html diff --git a/concepts/datetime/introduction.md b/concepts/datetime/introduction.md index 2b9513189..d4fbd5960 100644 --- a/concepts/datetime/introduction.md +++ b/concepts/datetime/introduction.md @@ -86,4 +86,14 @@ printer.format(date); // => "December 3, 2007" ``` +A locale can also be specified when creating the custom format to format and parse for different regions: + +```java +DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.FRENCH).format(date); +// => décembre 3, 2007 + +DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.of("pt")).format(date); +// => dezembro 3, 2007 +``` + [iso-8601]: https://en.wikipedia.org/wiki/ISO_8601 diff --git a/exercises/concept/booking-up-for-beauty/.docs/introduction.md b/exercises/concept/booking-up-for-beauty/.docs/introduction.md index ed132331c..57768dafe 100644 --- a/exercises/concept/booking-up-for-beauty/.docs/introduction.md +++ b/exercises/concept/booking-up-for-beauty/.docs/introduction.md @@ -88,4 +88,14 @@ printer.format(date); // => "December 3, 2007" ``` +A locale can also be specified when creating the custom format to format and parse for different regions: + +```java +DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.FRENCH).format(date); +// => décembre 3, 2007 + +DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.of("pt")).format(date); +// => dezembro 3, 2007 +``` + [iso-8601]: https://en.wikipedia.org/wiki/ISO_8601