How to Display Time in HTML

Open a simple text editor such as Notepad or Notepad++ on Windows or TextEdit on a Macintosh., Begin an HTML document consisting of the following code., Save the page., Open the file.

4 Steps 1 min read Easy

Step-by-Step Guide

  1. Step 1: Open a simple text editor such as Notepad or Notepad++ on Windows or TextEdit on a Macintosh.

    <html> <head> <script type="text/javascript"> function startTime() { var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); // add a zero in front of numbers<10 m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTime()'

    500); } function checkTime(i) { if (i<10) { i="0" + i; } return i; } </script> </head> <body onload="startTime()"> <div id="txt"></div> </body> </html>

    Personalize the file's name to make it easy to distinguish when you have you viewer read the page.

    This will give you a HTML link instead of a JavaScript one. , You can see your digital clock in HTML.
  2. Step 2: Begin an HTML document consisting of the following code.

  3. Step 3: Save the page.

  4. Step 4: Open the file.

Detailed Guide

<html> <head> <script type="text/javascript"> function startTime() { var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); // add a zero in front of numbers<10 m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTime()'

500); } function checkTime(i) { if (i<10) { i="0" + i; } return i; } </script> </head> <body onload="startTime()"> <div id="txt"></div> </body> </html>

Personalize the file's name to make it easy to distinguish when you have you viewer read the page.

This will give you a HTML link instead of a JavaScript one. , You can see your digital clock in HTML.

About the Author

B

Beverly Powell

Brings years of experience writing about organization and related subjects.

55 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: