Time and date
-
Am not sure what I’ve done wrong. The below code is supposed to show the time and date as Time|Date: 16:08:24 31/3/2013, however its now showing up as Time|Date: 16:08:24 0/3/2013…
<script>
function startTime()
{
var today=new Date();
var d=today.getDay(); //---Day Sunday
var dt=today.getDate(); //---Date 1-31
var mt=today.getMonth() + 1; //---Month
var y=today.getFullYear();//---Year
var h=today.getHours(); //---Hours
var m=today.getMinutes(); //---Mintutes
var s=today.getSeconds(); //---Seconds
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML= "Time|Date:"+" "+h+":"+m+":"+s+ " " + d+"/"+mt+"/"+y;
t=setTimeout(function(){startTime()},500);
}function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>Note: Everything else is fine except for the date, what with it bring up '0' instead of '31'
-
Am not sure what I’ve done wrong. The below code is supposed to show the time and date as Time|Date: 16:08:24 31/3/2013, however its now showing up as Time|Date: 16:08:24 0/3/2013…
<script>
function startTime()
{
var today=new Date();
var d=today.getDay(); //---Day Sunday
var dt=today.getDate(); //---Date 1-31
var mt=today.getMonth() + 1; //---Month
var y=today.getFullYear();//---Year
var h=today.getHours(); //---Hours
var m=today.getMinutes(); //---Mintutes
var s=today.getSeconds(); //---Seconds
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML= "Time|Date:"+" "+h+":"+m+":"+s+ " " + d+"/"+mt+"/"+y;
t=setTimeout(function(){startTime()},500);
}function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>Note: Everything else is fine except for the date, what with it bring up '0' instead of '31'