Display clock!
Moderator: General Moderators
Display clock!
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!
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!
- Frozenlight777
- Forum Commoner
- Posts: 75
- Joined: Wed May 28, 2008 12:59 pm
Re: Display clock!
analog or digital, lets be specific. There's so many ways to do this
Its also done mostly with javascript maybe a little php.
Its also done mostly with javascript maybe a little php.
Re: Display clock!
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!
maybe it's a very fancy clock
Re: Display clock!
Hehe.. It's not that fancy...
I just want to add this feature, does it matter why that much!
I'd say analog!
I just want to add this feature, does it matter why that much!
I'd say analog!
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: Display clock!
onion++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?
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!
Kieran Huggins, thanks for your reply!
But to be honest i can type "JavaScript Analog Clock" in google too!
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!
But to be honest i can type "JavaScript Analog Clock" in google too!
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!
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.
- Jasheppard
- Forum Newbie
- Posts: 24
- Joined: Tue Jun 17, 2008 11:44 pm
Display clock! - Using php mixed with javascript
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>
Oh and its a 24 hour clock. You could change if you want.
Re: Display clock!
Thanks Jasheppard!