Create a function getDays, pass a date, and return the day of the year that date is.
Method 1. Add all the days and dates of the month before a time period
function getDays(year,month,date){
var n=new Date(year,month-1,date)
var tow= year%4===0 && year%100 !==0 || year%400===0 ? 29:28
var arr=[31,tow,31,30,31,30,31,31,30,31,30,31]
for(var i=0,sum=0; i<month-1;i++){
sum=sum+arr[i]
}
return sum+date
}
console.log(getDays(2022,9,6))
Method 2: Subtract the initial time of the year from the passed time to get the number of days
function getDays(year,month,date){
var d1=new Date(year,month-1,date)
var d2=new Date(year,0,0)
var d3=d1.getTime()-d2.getTime()
return d3/(24*60*60*1000)
}
console.log(getDays(2022,9,6))