My application includes Java 21 on the server side and React.js on the client side. According to the Locale
, I must get a list/array of weekdays. I have no limits on dependencies to use, as long as they are free/open-source.
I can do that in Java using the following code (didn’t invest too much time writing it) and calling an API from the client to get it, but I want something that is JavaScript and if I can save the API request:
String[] weekDays = DateFormatSymbols.getInstance().getWeekdays();
System.out.print("weekDays:nt");
Arrays.stream(weekDays).forEach(x -> System.out.print(x + ", "));
System.out.println();
**Output:**
daysOfWeek:
, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
The code in Java for weekdays in German:
String[] daysOfWeekGER = DateFormatSymbols.getInstance(Locale.GERMAN).getWeekdays();
System.out.print("daysOfWeekGER:nt");
Arrays.stream(daysOfWeekGER).forEach(x -> System.out.print(x + ", "));
System.out.println();
**Output**
daysOfWeekGER:
, Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag,
I am looking for something similar in JavaScript.
Creating a hardcoded array for every language is impractical and wastes time and effort.