Show Current Date/Time on Web Page by Zyvxn | JavaScriptSource

Show Current Date/Time on Web Page by Zyvxn

Zyvxn Mar 17, 2016

Abstract

This script shows you the simple code to display the current date on your Web page.

Description

This script shows you the simple code to display the current date on your Web page. This allows your page to look much more dynamic and less "dated" as it will always have the current date displayed. The code shows a couple of different standard formats that can be used.

Code Snippet

<html>
<head>
<script language="JavaScript">
function GrabTheDateFunction()
{
   // Get a the current date, then format it for display
   var thisDate = new Date();

   document.write("<p>The current date is: ");
   document.write(thisDate.toDateString());
   document.write("</p>");
}

// other values to use to display date:
// thisDate.toDateString() --> Thu Mar 17 2016
// thisDate.toISOString()  --> 2016-03-17T13:12:18.519Z
// thisDate.toGMTString()  --> Thu, 17 Mar 2016 13:12:18 GMT
// thisDate.toUTCString()  --> Thu, 17 Mar 2016 13:12:18 GMT
// thisDate.toTimeString() --> 09:12:18 GMT-0400 (Eastern Daylight 

Time)

</script>

</head>
<body>
<script language="JavaScript">
    GrabTheDateFunction();
</script>
<h1>The Sample Page</h1>
<p>Let's see this work!</p>
</body>
</html>

Leave a Response

(0 comments)