The getFullYear() method of the Date object returns the year for the date according to local time. Use this method instead of the getYear().

    
    const date = new Date('August 6, 23 10:20:20');

    const year = date.getFullYear();

    console.log(year);
    // 2023