Automatically Update the Current Month

This code dynamically changes the month on your website so you don't have to.

Copy Code

<script> // Get the current month var month = new Date().getMonth(); // Get the list of months var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; // Display the current month document.getElementById("current-month").innerHTML = months[month] </script>

<script>
// Get the current month
var month = new Date().getMonth();

// Get the list of months
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

// Display the current month
document.getElementById("current-month").innerHTML = months[month]
</script>

This one's pretty simple to use. Just wrap whatever text element you're using in a <span></span> and then give it an ID of current-month.

Once you do that, the text that is wrapped in that span will display whatever the current month is.

A portrait of Dalton Craighead, a Web Designer and Web Developer.
Dalton Craighead
Web Design & Development
Get in touch