I want to display in my i18n-ed application a list of 7 working days:
Sunday, Monday, Tuesday... Saturday
I rely on the Intl global object to format the date / time, but I cannot find an easy way to get only the names of the days of the week.
I thought I could add a few days to EPOCH to get to the first day of the week, but I canβt find the formatting print only on a weekday.
var date = new Date(0);
date.setDate(4 + day);
for (var i = 0; i < 7; i++) {
var weekday = new Intl.DateTimeFormat(["en"], {
weekday: "short"
}).format(date);
console.log(weekday);
}
Conclusion:
Sunday, January 4, 1970
Monday, January 5, 1970
Tuesday, January 6, 1970
Wednesday, January 7, 1970
Thursday, January 8, 1970
Friday, January 9, 1970
Saturday, January 10, 1970
Required Conclusion:
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
I would also like to have a shorter version of days, for example Sun, Mon, Tue....
Alternatively, is there a way to get the day of the week strings from Intl? I tried to examine the object through the console, but I could not find them.