Nov 22, 2009

Counting Down To A Time - php or java?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting

Counting Down To A Time - php or java?

Supa Comix
Hey i have been searching google and websites to find the answer to my question but i just get blasted with a bunch of code that isn't explained...

So i would like to know how, in either php or java how i would get something to count down to a certain time, but not specifically a time, more like count down in days, hours, minutes and seconds and not require a refresh... like it count downs on the page every second... And that i can specify the days, hours etc in the start of the function such as

function countdown($days, $hours, $minutes, $seconds){

}

Thanks

Comment/Reply (w/o sign-up)

Jimmy89
I am assuming, by Java, you meant JavaScript - which would be a much easier alternative.

I copied this code from http://www.hashemian.com
CODE
<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>


As you said, you've been blasted with heaps of code without explanations - so I'll explain this for you.
1 TargetDate - This is the date (and time) that you are counting down too!
2 BackColor - This is for the graphical side of it, change this to match your website
3 ForeColor - Whatever colour you want your text, this is it!
4 CountActive - Whether the timer is counting down or not
5 CountStepper - How much to count down each time (make time faster by increasing this value tongue.gif) best to leave this one!
6 LeadingZero - Display zero in front of values (e.g. 04 days left)
7 DisplayFormat - How the values will be displayed, change to whatever suits you!
8 FinishMessage - This is what is displayed when the countdown is finished!

the very last line
CODE
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>

tells the browser where to look for the javascript file. If you want, you can download this file and host it locally (with your website) and change the address as necessary.

Good Luck
-jimmy

P.S If you want to, search on google for javascript countdown timers, theres heaps of websites and most of them should have explanations.

 

 

 


Comment/Reply (w/o sign-up)

Supa Comix
ace. Thanks that is exactly what im looking for. Thanks a bunch biggrin.gif

Comment/Reply (w/o sign-up)

Supa Comix
One last question. Say if i was recalling a date and time variable from a mysql database using php, in order to set the time could i just set the time

Targetdate = <?php echo($date . $time); ?>; ?

Comment/Reply (w/o sign-up)

Supa Comix
erm if anyone knows the answer to this then please answer biggrin.gif

Comment/Reply (w/o sign-up)

pyost
If $date and $time are properly formed, there should be no problems.

Comment/Reply (w/o sign-up)

FeedBacker
How can I "center" the display message & finish message in the countdown timer? Thanks.

-reply by kevin moore

Comment/Reply (w/o sign-up)

Jared
QUOTE(FeedBacker @ Mar 9 2008, 01:36 PM) *
How can I "center" the display message & finish message in the countdown timer? Thanks.

-reply by kevin moore


Is this what you're looking for?

CODE
<body style="margin: 32pt;">
<center style="font-family: tahoma; font-size: 8pt;">
<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "white";
ForeColor = "midnightblue";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
</center>
</body>

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for counting, time, php, java,
advertisement



Counting Down To A Time - php or java?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com