how to get current month and year in javascript code example

Example 1: javascript get current month start and end date

var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);

Example 2: javascript getmonth

new Date().getMonth(); //note that Jan=0, Dec=11 (annoying I know)

Example 3: current month in javascript

// Find current month in JavaScript
const localDate = new Date();
const months = [
  'January',
  'February',
  'March',
  'April',
  'May',
  'June',
  'July',
  'August',
  'September',
  'October',
  'November',
  'December',
];
let currentMonth = months[localDate.getMonth()];
console.log(currentMonth);

Example 4: get current month of year in number javascript

var today = new Date();
var month = today.getMonth(); // Returns 9
console.log(month); // Output: 9