Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Can anyone tell me how to display the current month and year in this format “October 2012” in JQuery or JavaScript code ? 

1 Answer

0 votes
by (19.7k points)

JavaScript doesn’t have a native strftime. If you have an element with ID of date in your HTML, follow the below code: 

window.onload = function() {

    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];;

    var date = new Date();

    document.getElementById('date').innerHTML = months[date.getMonth()] + ' ' + date.getFullYear();

};

Interested in Java? Check out this Java Certification by Intellipaat.   

Related questions

0 votes
1 answer
asked Dec 30, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Apr 9, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
asked Feb 16, 2021 in Web Technology by Jake (7k points)

Browse Categories

...