Submit your email address and receive
article and product notifications. Your email is safe with us.
Getmonth function using date object
We can use Date object in JavaScript to collect the current month by using getMonth function. We will try to print the present month name by using this getMonth function. Note that getMonth function returns number of month from 0 to 11. That is, it will return 0 if the month is January and will return 1 if the month is February and so on. It will return 11 for the month December.
To display the month name in full, we will write one array with all the month names inside it. Then based on the value returned by getMonth function we will display the corresponding element from this month array.
We will connect our button to display the current month in an alert window. Here is the demo.
Here is the code.
<html>
<head>
<title>(Type a title for your page here)</title>
<script type=\"text/javascript\">
function show_now(){
var my_month=new Date()
//var dt = new Date(\"Aug 16, 2005 05:55:00\");