Javascript - Date & Time?

Rip the Jacker

Diamond Member
Dec 29, 2004
5,415
1
76
Hey fellow lurkers of Software - Apps, Programming and Games,

I'm looking for a script/code that has the date & time in Javascript. I know I can probably GOOGLE this, but I'm looking for a reliable one that I can easily edit with CSS and many of you probably have done this with your other sites so I'm asking if you could help me out.

I want to insert this date & time into a <div> and customize it. I also prefer that it automatically updates by the second and uses the 24 hour format.

Thank you in advance.
 

Soccer55

Golden Member
Jul 9, 2000
1,660
4
81
Hopefully this is what you're looking for:

<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function startClock()
{
setInterval( "clock()", 1000 );
}

function clock()
{
var today = new Date()
var sec = today.getSeconds();
var min = today.getMinutes();
var hour = today.getHours();
var daynum = today.getDate();
var month = today.getMonth() + 1;
var year = today.getYear() + 1900;

var timedisplay = month + "/" + daynum + "/" + year + "" + hour + ":" + min + ":" + sec;
document.all.clock.innerHTML = timedisplay;
}
</SCRIPT>
</HEAD>
<BODY onLoad="startClock()">
<DIV ID="clock"></DIV>
</BODY>
</HTML>

If you want the date to be something like "May 28, 2005", you need to set up an array with all of the names of the months and use nameofarray[month] where var month = today.getMonth();

-Tom