javascript get month and year from date code example
Example 1: javascript get day of year
const dayOfYear = date => Math.floor((date - new Date(date.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24));
dayOfYear(new Date(2020, 04, 16));
Example 2: get year from date javascript
document.write(new Date().getFullYear());
Example 3: how to get only month and year in js
let dateObj = new Date();
let myDate = (dateObj.getUTCFullYear()) + "/" + (dateObj.getMonth() + 1)+ "/" + (dateObj.getUTCDate());
Example 4: get current month of year in number javascript
var today = new Date();
var month = today.getMonth();
console.log(month);