Tag Archives: month

Javascript: Month + Year

I recently needed to use javascript to write out the current month and year. Here, HTH…

<script type=”text/javascript”>
<!–
var currentMonthYear = new Date()
var monthNumber = currentMonthYear.getMonth() + 1
var year = currentMonthYear.getFullYear()
if (monthNumber==1) monthName=(‘January’);
else if (monthNumber==2) monthName=(‘February’);
else if (monthNumber==3) monthName=(‘March’);
else if (monthNumber==4) monthName=(‘April’);
else if (monthNumber==5) monthName=(‘May’);
else if (monthNumber==6) monthName=(‘June’);
else if (monthNumber==7) monthName=(‘July’);
else if (monthNumber==8) monthName=(‘August’);
else if (monthNumber==9) monthName=(‘September’);
else if (monthNumber==10) monthName=(‘October’);
else if (monthNumber===11) monthName=(‘November’);
else monthName=(‘December’);
document.write(monthName + ” ” + year)
//–>
</script>