Today's Date
/*
Examples From
JavaScript: The Definitive Guide, Fourth Edition
Legal matters: these files were created by David Flanagan, and are
Copyright (c) 2001 by David Flanagan. You may use, study, modify, and
distribute them for any purpose. Please note that these examples are
provided "as-is" and come with no warranty of any kind.
David Flanagan
*/
<html>
<head>
<title>Today's Date</title>
<script language="JavaScript">
// Define a function for use later on.
function print_todays_date() {
var d = new Date(); // Get today's date and time
document.write(d.toLocaleString()); // Insert it into the document
}
</script>
</head>
<body>
The date and time are:<br>
<script language="JavaScript">
// Now call the function we defined above.
print_todays_date();
</script>
</body>
</html>
Related examples in the same category