How to get the month name from Date using JavaScript?

03-May-2023

.

Admin

How to get the month name from Date using JavaScript?

Today, get month name from date using javascript is our main topic. you'll learn how to get the month name from date using javascript. if you want to see example of javascript - get month name from date then you are a right place. if you have question about get month name from date then I will give simple example with solution.

There are several ways to get the month name from a Date object in JavaScript. Here are a few examples:

Example 1: Using the toLocaleString() method


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>How to get the month name from Date using JavaScript? - NiceSnippets.Com</title>

</head>

<body>

</body>

<script type="text/javascript">

const date = new Date();

const monthName = date.toLocaleString('default', { month: 'long' });

console.log(monthName);

</script>

</html>

Example 2: Using an array of month names

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>How to get the month name from Date using JavaScript? - NiceSnippets.Com</title>

</head>

<body>

</body>

<script type="text/javascript">

const date = new Date();

const months = ['January', 'February', 'March', 'April', 'May', 'June',

'July', 'August', 'September', 'October', 'November', 'December'];

const monthName = months[date.getMonth()];

console.log(monthName);

</script>

</html>

Example 3: Using the Intl.DateTimeFormat() constructor

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>How to get the month name from Date using JavaScript? - NiceSnippets.Com</title>

</head>

<body>

</body>

<script type="text/javascript">

const date = new Date();

const formatter = new Intl.DateTimeFormat('en-US', { month: 'long' });

const monthName = formatter.format(date);

console.log(monthName);

</script>

</html>

#JavaScript