js gets the date week number and calculates the start and end dates of the current week based on the week number (starts on Sunday and ends on Saturday)

js gets the date week number and calculates the start and end dates of the current week based on the week number (starts on Sunday and ends on Saturday)

calendar pictures

Insert image description here

code

Get the week number of a date (week of the year)

Explanation: The parameter passed by dateTime here is in string form ('2021-02-28')

  getWeek (dateTime) {
        let temptTime = new Date(dateTime)
        let weekday
        // 如果是周日,则设为7
        if (temptTime.getDay() == 6) {
          weekday = 7
        } else {
          weekday = temptTime.getDay()
        }
        temptTime.setDate(temptTime.getDate() - weekday + 6)
        let firstD

Guess you like

Origin blog.csdn.net/wh13821662259/article/details/114697974