js months code example
Example 1: javascript months array
'use strict';
(function(d){
var mL = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var mS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
d.prototype.getLongMonth = d.getLongMonth = function getLongMonth (inMonth) {
return gM.call(this, inMonth, mL);
}
d.prototype.getShortMonth = d.getShortMonth = function getShortMonth (inMonth) {
return gM.call(this, inMonth, mS);
}
function gM(inMonth, arr){
var m;
if(this instanceof d){
m = this.getMonth();
}
else if(typeof inMonth !== 'undefined') {
m = parseInt(inMonth,10) - 1;
}
return arr[m];
}
})(Date);
Example 2: javascript getmonth
new Date().getMonth();
Example 3: getmonth javascript
var date=new Date();
var month=new Array();
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
var n = month[date.getMonth()];