chmpdog Posted November 26, 2008 Share Posted November 26, 2008 hello, I wanted to create a script where at 6pm it will display: 'it is 6pm'; (of course I will add in something), until 6pm it will display how long in hours, minutes, seconds Now Im not too sure where to start on this one. Can anyone point me in the right direction? Thanks, Charlie Also, if you happen to know a way to auto-update the time using javascript that would be appreciated. Quote Link to comment Share on other sites More sharing options...
awpti Posted November 26, 2008 Share Posted November 26, 2008 Why not just use javascript? Kinda pointless to do it in PHP and then spend the time writing the necessary JS/AJAX Functionality to check and recheck server-time. Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted November 26, 2008 Share Posted November 26, 2008 A slightly involved code is needed for this but i can get you started. Yeah, you really need only javascript for this. I wrote this clock a while back, it's obviously not what you need exactly, but it'll show you date/time manipulation in js. function clock() { var time = new Date(); var hours = time.getHours(); var mins = time.getMinutes(); var secs = time.getSeconds(); if (secs < 10) { var sec = "0"+secs; } else { var sec = secs; } if (mins < 10) { var min = "0"+mins; } else { var min = mins; } if (hours > 12) { var hour = hours - 12; } else { var hour = hours; } if (hours < 12) { var ap = "AM"; } else { var ap = "PM"; } document.getElementById("time").innerHTML="The time is: "+hour+":"+min+":"+sec+" "+ap; setTimeout("clock()", 1000); } [code] Quote Link to comment Share on other sites More sharing options...
chmpdog Posted November 26, 2008 Author Share Posted November 26, 2008 Normally I would just use javascript, but I need it to be secure. With javascript just use firebug, and you can get it to display the final message prior to 6pm, but if I use php. Well you cant edit the server... Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted November 26, 2008 Share Posted November 26, 2008 alright, well read up on comparing timestamps. I'm pretty sure there are a few good functions here http://www.php.net/time All you need to do is get the current time, if its not six, get the timestamp for 6 of the current day (something like time( "6:00 pm " . date( 'F d Y' ) )), compare it to the time the page was loaded, and output the wait time. I guess you could get fancy and use ajax to update automatically, in which case a simple GET command is all you need. Tutorials for this at: http://w3schools.com/ajax/ajax_server.asp or http://phpgfx.com/tutorials/?action=read&id=49 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.