Codes for HTML current date

Asked By 0 points N/A Posted on -
qa-featured

Hi,

I was wondering how to show the current date on an HTML document using notepad.

Thanks!

SHARE
Best Answer by Taylor Laura
Answered By 0 points N/A #162035

Codes for HTML current date

qa-featured

Hi there. You can get codes to do that in the following links: www.freevbcode.com/ShowCode.asp?ID=86

You can also use java script to display the current date and time.

Many people disagree that html can do that because it doesn't interact with the user and the machine.

To use JavaScript to do that, here's a code webdesign.about.com/od/examples/l/blaa050701a_date.htm

Enjoy

Best Answer
Best Answer
Answered By 15 points N/A #162036

Codes for HTML current date

qa-featured

Hi,

It would be impossible to use just an HTML language alone to show the current time or date.  

You need a language that could interact with your computer and with the user, so you can eventually capture the current time.  

This is where Java scripting comes.  

The good news though is that you can integrate both programs to display the time and date on your browser.

First start creating the HTML skeleton:

<html>

<head>

<title>EXAMPLE OF TIME AND DATE</title>

</head>

<body>

</body>

</html>

Then add meta elements after the <head> tag.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

The meta elements written above will tell your browser that it's going to use JavaScript, html and CSS program in your current program.  

In your <body> insert the following program:

<script type="text/javascript">

document.write ('<p>Current time is: <span id="date-time">', new Date().toLocaleString(), '</span>.</p>')

if (document.getElementById) onload = function () {

setInterval ("document.getElementById ('date-time').firstChild.data = new Date().toLocaleString()", 50)}

</script>

This program is a standard Javascript program that will display the current time and date in your browser.  Combining it all together this is how it will look like:

I coded this program in notepad, and it worked so far.

Good luck.

Related Questions