Skip to content
Advertisement

How to get the weekday names using Intl?

I’d like to display in my i18n-ed app a list of the 7 weekdays:

JavaScript

I rely on the Intl global object for formatting date/time but I can’t find an easy way to get only the weekday names.

I thought I could add some days to the EPOCH time, to reach the first day of the week, but I’m failing to find a formatter printing just the weekday.

JavaScript

Output:

JavaScript

Desired output:

JavaScript

I also would like to have a shorter version of the days, such as Sun, Mon, Tue....

Alternatively, is there a way to get the weekday strings from Intl? I tried to explore the object via console but I couldn’t find them.

Advertisement

Answer

I was misled because I was using the Intl polyfill, which does not support yet { weekday: "short" } as option.

Using native Intl implementations works as expected.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement