• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 18.  JavaScript Essentials > Adding the Current Date and Time

Adding the Current Date and Time

Nothing makes your page seem more current than adding the date and the time. While they're a bit more complicated to format in a particular way, just adding them is not difficult at all.

To add the current date and time to your page:

1.
Place the cursor where you'd like the time to appear.

2.
Type <SCRIPT LANGUAGE="javascript"> to begin your script.

3.
Type <!-- to hide the script from older browsers.

4.
On the next line, type document.write(

5.
If desired, type "<TAG>"+, where TAG is the HTML formatting you'd like to apply to the date.

6.
Date()

7.
If you've added formatting in step 5, type +"<\/TAG>", where TAG is the corresponding closing tag. Notice the extra backslash.

8.
Type ) to finish the document.write function.

9.
On the next line, type // --> to finish hiding the script.

10.
Type </SCRIPT>.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint