Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I display todays Date/Time on my website?

Status
Not open for further replies.

blondebier

Programmer
Jun 19, 2003
142
GB

I'd like to display the current date/time on a website. Does anyone know how I can do this in a HTML page?

Cheers for any help.
 
Here is a very simple test page that you can copy-paste to test how to do this.

I have set this to configure 2 strings... one is the date information, one if the time information. These are both calculated at the top of the page, and then written to the page at the appropriate place in your HTML.

Code:
<html>
<head>
<script type="text/javascript">
dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
monName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
dateExt = new Array ("","st","nd","rd","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","st","nd","rd","th","th","th","th","th","th","th","st");
var today = new Date();
var _dateString = dayName[today.getDay()] + ", " + monName[today.getMonth()] + " " + today.getDate() + dateExt[today.getDate()];
var _timeString = today.getHours() + "h " + today.getMinutes() + "m " + today.getSeconds() + "s";
</script>
</head>
<body>
<script type="text/javascript">document.write(_dateString + " (" + _timeString + ").");</script>
</body>
</html>

The output will look something like this:
Monday, April 19th (10h 21m 55s).

Hope this gets you started, and gives you enough example to take it form here. Drop a message in the forum if you need more help!

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top