Jump to content

Trigger an event at 6pm?


chmpdog

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/134320-trigger-an-event-at-6pm/
Share on other sites

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]

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.