How to get localized short names of the days of week starting from monday to sunday in javascript?
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
How to get localized short names of the days of week starting from monday to sunday in javascript?
3
Answers
Here is example with french locale:
Another example with long names in english:
You seem to be over complicating things. You can initialise the date used for getting the day names to a date that is the day you want to start on. Also, toLocaleString is simpler and accepts the same options as DateTimeFormat without the overhead.
Here’s a simple for loop version:
And a more obfuscated one liner:
If you play with it a little more, you can have the caller specify the first day of the week as the ECMAScript day number and use that when initialising the date: