Tutorials » Javascript tutorials »

Javascript date object's getMonth()


This article explains date object's getMonth() method


getMonth()



returns current month code of current Date or month code of specified date.




<html>

<head>

<script>

function f()

{

var date = new Date ("August 21, 2006 01:15:00")

document.write(date.getMonth()+1)

}

</script>

</head>

<body>

<input type ="button" value ="Click to get month" onclick ="return f();" >

</body>



As get month returns an integer between 0 and 11, it will return 7 for August month
In order to get correct results we increment it by 1 .We get output as 8.




Next Chapter: JavaScript Date object's getYear()
Previous Chapter: Date object's' getDate() method
More Chapters: Javascript Tutorials
More Tutorials: Tutorial Index



Top Contributors
Today
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    srirama
    More...
     
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India