0

I'm trying to get the days of the week from the date of the specific day (e.g today is wednesday so I'd like to get today plus the 7 days after today) using the INTL. I have managed to get today's date but I'm unsure how to get the rest of the days.

              function daysForLocale(localeName = 'en', weekday = 'long') {
                const format = new Intl.DateTimeFormat(localeName, { weekday }).format;
                return [...Array(1).keys()]
                  .map((day) => format(new Date()));
              }
              console.log(daysForLocale());

output:

["Wednesday"]
["Wednesday"]
["Wednesday"]
["Wednesday"]
["Wednesday"]
["Wednesday"]
["Wednesday"]

Desired Output

["Thursday"]
["Friday"]
["Saturday"]
["Sunday"]
["Monday"]
["Tuesday"]
["Wednesday"]
DannyMeister
  • 1,281
  • 1
  • 12
  • 21

1 Answers1

0

Please use this code.

    function daysForLocale(localeName = 'en', weekday = 'long') {
        const format = new Intl.DateTimeFormat(localeName, { weekday }).format;
        const today = new Date();
        return [...Array(7).keys()]
          .map((val, index) => [format(new Date(today.getTime() + 3600 * 24 * 1000 * (index + 1)))]);
    }
    console.log(daysForLocale());
Kirill Savik
  • 1,228
  • 4
  • 7