Page 1 of 1

Display clock!

Posted: Tue Jun 24, 2008 2:22 pm
by dgrzalja
Hy!

I'm adding time display to my web site and i thought on adjusting the clock
so that it displays in real time! Can this be done with PHP and how?
I know that there may be some finished scripts out there, but
i just want to know how it's made.... Thanks!

Re: Display clock!

Posted: Tue Jun 24, 2008 2:27 pm
by Frozenlight777
analog or digital, lets be specific. There's so many ways to do this

Its also done mostly with javascript maybe a little php.

Re: Display clock!

Posted: Tue Jun 24, 2008 2:55 pm
by onion2k
Every single user in the whole world has a clock on the computer they're viewing your website on, so why would they want to see the time on your site?

Re: Display clock!

Posted: Tue Jun 24, 2008 3:10 pm
by Eran
maybe it's a very fancy clock

Re: Display clock!

Posted: Tue Jun 24, 2008 3:33 pm
by dgrzalja
Hehe.. It's not that fancy... :lol:
I just want to add this feature, does it matter why that much!
I'd say analog! :D

Re: Display clock!

Posted: Tue Jun 24, 2008 4:15 pm
by Kieran Huggins
onion2k wrote:Every single user in the whole world has a clock on the computer they're viewing your website on, so why would they want to see the time on your site?
onion++

but for the sake of playing around... go for it!

Javascript is the answer: http://www.google.com/search?ie=UTF-8&o ... alog+clock

Re: Display clock!

Posted: Tue Jun 24, 2008 5:32 pm
by dgrzalja
Kieran Huggins, thanks for your reply!
But to be honest i can type "JavaScript Analog Clock" in google too! :teach:
I asked if it can be done in PHP!
So the answer is NO use JavaScript with maybe little PHP!
And I am trying to get this done because i want to learn and learn
about PHP all i can, and i thought i would get a normal answer instead
of making fun of the idea, because not all of us are so pro! Thanks!

Re: Display clock!

Posted: Tue Jun 24, 2008 5:38 pm
by Eran
PHP is a server side language and can not change data dynamically in the browser after it has been loaded. Unless you want to refresh your screen every second, to display a live clock you would have to employ javascript.

Display clock! - Using php mixed with javascript

Posted: Tue Jun 24, 2008 9:16 pm
by Jasheppard

Code: Select all

 
<script type="text/javascript">
var currenttime = '<?php print date("F d, Y H:i:s", time())?>' // Where php says the current time, then javascript keeps it counting.
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var serverdate=new Date(currenttime)
function padlength(what){
var output=(what.toString().length==1)? "0"+what : what
return output
}
function displaytime(){
serverdate.setSeconds(serverdate.getSeconds()+1)
var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()
var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds())
document.getElementById("servertime").innerHTML="<i>"+datestring+" "+timestring+"</i>"
}
window.onload=function(){
setInterval("displaytime()", 1000)
}
</script>
<span id="servertime"><!-- Server time will automatically be placed here --></span>
 
eg: June 24, 2008 10:11:10

Oh and its a 24 hour clock. You could change if you want.

Re: Display clock!

Posted: Wed Jun 25, 2008 4:41 pm
by dgrzalja
Thanks Jasheppard!