I'm new to JS so, please bear with me.
I'm playing/learning with dates and time functions. Somehow, I got stuck here. I can't see why it isn't working. It is a very simple code. Here is the HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Testing</title>
<script type="text/javascript" src="scripts/jquery-1.6.3.min.js"></script>
<script type="text/javascript" src="scripts/displayTime.js"></script>
</head>
<body>
<h2>Displaying Date & Time</h2>
<p>Today's Date is:
<strong>
<script type="text/javascript">
document.write(printDate());
</script>
</strong></p>
<p>The time is:
<strong>
<script type="text/javascript">
document.write(printTime());
</script>
</strong></p>
</body>
</html>
and the JS file "displayTime.js" in a separated folder:
function printDate() {
var month,today,year,mydate;
var now = new Date();
month = now.getMonth();
today = now.getDate();
year = now.getFullYear();
mydate = month + "/" + date + "/" + year;
return mydate;
}
function printTime() {
var hours,minutes,seconds,time;
var now = new Date();
hours = now.getHours();
minutes = now.getMinutes();
if (minutes<10) {
minutes = '0' + minutes;
}
seconds = now.getSeconds();
if (seconds<10) {
seconds = '0' + seconds;
}
time = hours + ":" + minutes + ":" + seconds;
return time ;
}
I got this output(copy & paste):
Displaying Date & Time
Today's Date is:
The time is: 18:39:51
Could you please help me understand why the date is not showing?
Thanks in advance
Bookmarks