milov.nl

Interaction design • webdevelopment • web art • photography

milov.nl : forum : coding : 'How to make a "refreshing" PHP date?'

How to make a "refreshing" PHP date? Aku, 050415 15:58
So, how is it possible to make "auto-refreshing" dates.

For example


<?php
echo date("r");
?>
 

So, this code would refresh the text printed on the screen each second.

Help! :D

-Aku-
YYYMKDCCLXXXVII.dsl.saunalahti.fi
Re: How to make a "refreshing" PHP date? Milo, 050415 17:21
Each second? In that case, a Javascript-based solution might be more appropriate. But as a proof-of-concept, the php would look like this:
<?php

// refresh after one second
header("Refresh: 1; URL=$PHP_SELF");

echo date("r");

?>
 
milov.demon.nl
Re: How to make a "refreshing" PHP date? Aku, 050416 15:25
Thank you for the solution. :)

How about the Javascript-based solution? How can that be done?

-Aku
YYYMKDCCLXXXVII.dsl.saunalahti.fi
Re: How to make a "refreshing" PHP date? Calm_Pear, 050417 11:36

<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
//<![CDATA[
<!--
function Clock() {
var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0){hours = 12;}
if (minutes <= 9){minutes = "0" + minutes;}
if (seconds <= 9){seconds = "0" + seconds;}
movingtime = hours + ":" + minutes + ":" + seconds + " " + dn;
document.getElementById("clock").innerHTML = movingtime;
setTimeout("Clock()", 1000)
}
window.onload = Clock;
//-->
//]]>
</script>
</head>
<body>

Currently, it's <span id="clock"></span>

</body>
</html>
 
h103091.upc-h.chello.nl
Pages: 1