| Display Today's Date This script shows you how to display today's date on a web
site. Both methods take the information from the user's system and displays it in
either regular text or as a graphic. The script is dynamic in that whenever you visit the
page, the date will update itself automatically. You can experiment with the samples below
by changing your system dates and refreshing the page.
- Standard Date - This simple script displays
the day, month, date, the time at the moment you entered the page, and the year. The time
is static with this display.
<script language="JavaScript">
<!--
var TodaysDate = new Date( )
document.write(TodaysDate);
//-->
</script>
- Graphical Date - The same information is
retrieved, but this time is displayed graphically. You can customize your own images
by creating different graphics for each item - month, day, date and year.
<script language="JavaScript">
<!--
var TodaysDate = new Date( )
var day = TodaysDate.getDay( )
var month = TodaysDate.getMonth( )
var date = TodaysDate.getDate( )
var year = TodaysDate.getYear( )
document.write("<img src='../gifs/days/"+day+".gif'>");
document.write("<img src='../gifs/months/"+month+".gif'>");
document.write("<img src='../gifs/dates/"+date+".gif'>")
document.write("<img src='../gifs/years/"+year+".gif'>");
//-->
</script>
- You must create different folders for each item (e.g., months
folder, days folder, etc.)
- The month and days require that you number your graphics
starting from "0". For example, January should be saved as
"0.gif" and February as "1.gif" in the months directory, while Sunday
should be saved as "0.gif" in the days folder, etc.
Back to Web Tips |