Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-28-2012, 04:48 AM   #1
grimz
Registered User
 
Join Date: Jun 2012
Posts: 6
Default Clock Countdown Function Help

Hello,

I was wondering if someone could break down the following code for me and make it a bit easier so that i can just set a start date / end date.

Thanks.
Code:
function displayDifference()
{
    nowTime = new Date();
    hoursLeft = ((((16-nowTime.getDate())*24) + (20 - nowTime.getHours())));
	//hoursLeft = (4 - nowTime.getDate()) * 24 + (19 - nowTime.getHours());
    if (hoursLeft >= 0)
    {
        timeRemaining.text = hoursLeft + ":" + padString(59 - nowTime.getMinutes()) + ":" + padString(59 - nowTime.getSeconds()) + "";
    }
    else
    {
        timeRemaining.text = "0H 0M 0S";
    } // end else if
} // End of the function
What i want to do is have a Start date of a value such as July 1st
and end date of July 31st

i'm not sure how similar this is to javascript esentially i want it to be like this.

Code:
/* Date Animation  starts here*/
				$(function () {
				var austDay = new Date();
				var austDay = new Date("June 30, 2012 21:00:00"); 
				$('#countdown').countdown({until: austDay, layout: 
								'<div id="days" class="numbers">{dnn}</div>'+
								'<div class="spacer"></div>'+
								'<div id="hours" class="numbers">{hnn}</div>'+
								'<div class="spacer"></div>'+
								'<div id="minutes" class="numbers">{mnn}</div>'+
								'<div class="spacer"></div>'+
								'<div id="seconds" class="numbers">{snn}</div>'+
								'</div>'});
								});});

Last edited by grimz; 06-28-2012 at 04:50 AM.
grimz is offline   Reply With Quote
Old 06-28-2012, 11:03 PM   #2
grimz
Registered User
 
Join Date: Jun 2012
Posts: 6
Default Hello Countdown Timer

Hello,

I was wondering if someone could break down the following code for me and make it a bit easier so that i can just set a start date / end date.

Thanks.
Code:
function displayDifference()
{
    nowTime = new Date();
    hoursLeft = ((((16-nowTime.getDate())*24) + (20 - nowTime.getHours())));
	//hoursLeft = (4 - nowTime.getDate()) * 24 + (19 - nowTime.getHours());
    if (hoursLeft >= 0)
    {
        timeRemaining.text = hoursLeft + ":" + padString(59 - nowTime.getMinutes()) + ":" + padString(59 - nowTime.getSeconds()) + "";
    }
    else
    {
        timeRemaining.text = "0H 0M 0S";
    } // end else if
} // End of the function
What i want to do is have a Start date of a value such as July 1st
and end date of July 31st

i'm not sure how similar this is to javascript esentially i want it to be like this.

Code:
/* Date Animation  starts here*/
				$(function () {
				var austDay = new Date();
				var austDay = new Date("June 30, 2012 21:00:00"); 
				$('#countdown').countdown({until: austDay, layout: 
								'<div id="days" class="numbers">{dnn}</div>'+
								'<div class="spacer"></div>'+
								'<div id="hours" class="numbers">{hnn}</div>'+
								'<div class="spacer"></div>'+
								'<div id="minutes" class="numbers">{mnn}</div>'+
								'<div class="spacer"></div>'+
								'<div id="seconds" class="numbers">{snn}</div>'+
								'</div>'});
								});});
grimz is offline   Reply With Quote
Old 06-29-2012, 01:02 AM   #3
svenjoypro
DontJustEnjoyIt,SvEnjoyIt
 
svenjoypro's Avatar
 
Join Date: Sep 2005
Location: California
Posts: 1,389
Default

I think this will work for you:
ActionScript Code:
function displayDifference() {     var nowTime:Date = new Date();     var targetTime:Date = new Date(2012, 6, 30); // This is for July, notice months are like arrays, they start with 0         var nowS:int = nowTime.valueOf()/1000;     var tarS:int = targetTime.valueOf()/1000;         var diff:int = tarS - nowS;         var daysLeft:int = int(diff/86400);     diff -= (daysLeft*86400);     var hoursLeft:int = int(diff/3600);     diff -= (hoursLeft*3600);     var minutesLeft:int = int(diff/60);     diff -= (minutesLeft*60);     var secondsLeft:int = diff;         hoursLeft += (daysLeft*24);         trace(daysLeft);     trace(hoursLeft);     trace(minutesLeft);     trace(secondsLeft);         if (hoursLeft >= 0)     {         timeRemaining.text = padString(hoursLeft) + ":" + padString(minutesLeft) + ":" + padString(secondsLeft);     }     else     {        timeRemaining.text = "0H 0M 0S";     } // end else if } // End of the function

And on a side note, this is AS3
svenjoypro is offline   Reply With Quote
Old 06-29-2012, 04:46 PM   #4
grimz
Registered User
 
Join Date: Jun 2012
Posts: 6
Default

Quote:
Originally Posted by svenjoypro View Post
I think this will work for you:
ActionScript Code:
function displayDifference() {     var nowTime:Date = new Date();     var targetTime:Date = new Date(2012, 6, 30); // This is for July, notice months are like arrays, they start with 0         var nowS:int = nowTime.valueOf()/1000;     var tarS:int = targetTime.valueOf()/1000;         var diff:int = tarS - nowS;         var daysLeft:int = int(diff/86400);     diff -= (daysLeft*86400);     var hoursLeft:int = int(diff/3600);     diff -= (hoursLeft*3600);     var minutesLeft:int = int(diff/60);     diff -= (minutesLeft*60);     var secondsLeft:int = diff;         hoursLeft += (daysLeft*24);         trace(daysLeft);     trace(hoursLeft);     trace(minutesLeft);     trace(secondsLeft);         if (hoursLeft >= 0)     {         timeRemaining.text = padString(hoursLeft) + ":" + padString(minutesLeft) + ":" + padString(secondsLeft);     }     else     {        timeRemaining.text = "0H 0M 0S";     } // end else if } // End of the function

And on a side note, this is AS3
Thanks i'll let you know if it works.
what's the difference between AS2 and 3?
Also... if you dont mind me asking the function difference i posted
can you break down what it does?


hoursLeft = ((((16-nowTime.getDate())*24) + (20 - nowTime.getHours())));
My guess... 16 = the date it stops. *24 is the clock + 20 = timezone? - the current time?

am i close?
grimz is offline   Reply With Quote
Old 06-29-2012, 10:33 PM   #5
svenjoypro
DontJustEnjoyIt,SvEnjoyIt
 
svenjoypro's Avatar
 
Join Date: Sep 2005
Location: California
Posts: 1,389
Default

There's a lot of differences between AS2 and AS3, it's pretty much an entirely different language.

I'm not sure what all the equation means, I didn't take the time to try and figure it out.

My code gets the unix epoch time (the number of seconds since January 1, 1970) of both the current time and the targetDate. It then calculates the number of days, hours, minutes, and seconds difference between them. If you want a countdown to begin counting down you'll have to add more code. Look into the Timer class (that will allow you to call a function every 1 second).
svenjoypro is offline   Reply With Quote
Old 06-29-2012, 10:41 PM   #6
grimz
Registered User
 
Join Date: Jun 2012
Posts: 6
Default

Quote:
Originally Posted by svenjoypro View Post
There's a lot of differences between AS2 and AS3, it's pretty much an entirely different language.

I'm not sure what all the equation means, I didn't take the time to try and figure it out.

My code gets the unix epoch time (the number of seconds since January 1, 1970) of both the current time and the targetDate. It then calculates the number of days, hours, minutes, and seconds difference between them. If you want a countdown to begin counting down you'll have to add more code. Look into the Timer class (that will allow you to call a function every 1 second).
Ya that code you provided doesnt work.
can you break down what that function i posted does?
maybe i can come up with a way.

it says Action script 1.0 - 2.0 in my cs5 .fla file.
lemme know thanks!
grimz is offline   Reply With Quote
Old 06-29-2012, 10:48 PM   #7
svenjoypro
DontJustEnjoyIt,SvEnjoyIt
 
svenjoypro's Avatar
 
Join Date: Sep 2005
Location: California
Posts: 1,389
Default

hoursLeft = (((+ (20 - nowTime.getHours())));

(16-nowTime.getDate())*24
This gets the current date (the day of the month) so today would be the 29th. 16-29 = -13 it then multiplies that by 24 = -312.

(20 - nowTime.getHours())
This gets the current hour of the day, ie 13 for 1pm. 20 - 13 = -7.

-312 + -7 = -319

I'm not totally sure, but 16 is probably the target date, 20 is probably the target hour.
svenjoypro is offline   Reply With Quote
Old 06-29-2012, 10:53 PM   #8
grimz
Registered User
 
Join Date: Jun 2012
Posts: 6
Default

Quote:
Originally Posted by svenjoypro View Post
hoursLeft = (((+ (20 - nowTime.getHours())));

(16-nowTime.getDate())*24
This gets the current date (the day of the month) so today would be the 29th. 16-29 = -13 it then multiplies that by 24 = -312.

(20 - nowTime.getHours())
This gets the current hour of the day, ie 13 for 1pm. 20 - 13 = -7.

-312 + -7 = -319

I'm not totally sure, but 16 is probably the target date, 20 is probably the target hour.
yea that's what i gathered... man i just want an easier way to set the stop date. check the email i sent ya.
grimz is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:18 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.