Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  20] [ 5]  / answers: 1 / hits: 77202  / 12 Years ago, sat, october 6, 2012, 12:00:00

I'm trying to get a jquery or java-script code for displaying the current month and year in a div, but unable so far. I mean I want to display the current month and year in this format:October 2012 so that every month I don't need to edit it or anything.



I saw many questions here, but none shows how to display the variable in a div.



Any idea how to accomplish that?



Your help and ideas are much appreciated


More From » jquery

 Answers
30

JavaScript doesn't natively implement strftime, so you'll have to do something a bit less elegant:



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();
};


I'm assuming that you have an element with an id of date somewhere in your HTML.


[#82725] Thursday, October 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breanab

Total Points: 731
Total Questions: 95
Total Answers: 79

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
;