const date = new Date(); const dateArr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; const day = date.getDate(); const month = date.getMonth() + 1; const year = date.getFullYear(); let numOfYear = 0; for ( let i = 1; i < month; i++) { numOfYear += dateArr[i]; } numOfYear += day; if (month > 2 && (year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0)) { numOfYear += 1; }
|