Display clock!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dgrzalja
Forum Newbie
Posts: 7
Joined: Mon Jun 16, 2008 3:45 pm

Display clock!

Post 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!
User avatar
Frozenlight777
Forum Commoner
Posts: 75
Joined: Wed May 28, 2008 12:59 pm

Re: Display clock!

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Display clock!

Post 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?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Display clock!

Post by Eran »

maybe it's a very fancy clock
dgrzalja
Forum Newbie
Posts: 7
Joined: Mon Jun 16, 2008 3:45 pm

Re: Display clock!

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Display clock!

Post 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
dgrzalja
Forum Newbie
Posts: 7
Joined: Mon Jun 16, 2008 3:45 pm

Re: Display clock!

Post 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!
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Display clock!

Post 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.
User avatar
Jasheppard
Forum Newbie
Posts: 24
Joined: Tue Jun 17, 2008 11:44 pm

Display clock! - Using php mixed with javascript

Post 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.
dgrzalja
Forum Newbie
Posts: 7
Joined: Mon Jun 16, 2008 3:45 pm

Re: Display clock!

Post by dgrzalja »

Thanks Jasheppard!
Post Reply