How to get the number of days in a month
P粉354948724
P粉354948724 2023-08-25 13:55:10
0
2
477

I made a countdown timer and need to get the number of days in a month and subtract the number of days that have passed (eg: 30 days in September minus 8 days - today's date). Now I need to manually enter:

const end = new Date(2021, 8, 30, 13, 0,12, 12);

P粉354948724
P粉354948724

reply all (2)
P粉916553895

You can use the following code to get the number of days in a month:

const getDays = (year, month) => new Date(year, month, 0).getDate() const days = getDays(2021, 8) console.log(days)
    P粉792673958

    Number of days remaining in this month

    var currentDate = new Date(); var currentYear = currentDate.getFullYear(); var currentMonth = currentDate.getMonth(); var currentMonthLastDate = (new Date(currentYear, currentMonth, 0)).getDate(); var daysLeftInMonth = currentMonthLastDate - currentDate.getDate(); console.log(daysLeftInMonth);
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!