Date countdown reset

I've been using the below code for a countdown timer that ends on 5th April 2012. However when the countdown reaches this date I'll like it to automatically start counting down to 5th April 2013. Currently it goes into minus numbers. Thanks in advance for any help.
this.onEnterFrame = function() {
    var today:Date = new Date();
    var currentYear = today.getFullYear();
    var currentTime = today.getTime();
    var targetDate:Date = new Date(currentYear,3,5);
    var targetTime = targetDate.getTime();
    var timeLeft = targetTime - currentTime;
    var sec = Math.floor(timeLeft/1000);
    var min = Math.floor(sec/60);
    var hrs = Math.floor(min/60);
    var days = Math.floor(hrs/24);
    sec = String(sec % 60);
    if (sec.length < 2) {
    sec = "0" + sec;
    min = String(min % 60);
    if (min.length < 2) {
    min = "0" + min;
    hrs = String(hrs % 24);
    if (hrs.length < 2) {
    hrs = "0" + hrs;
    days = String(days);
    var counter:String = days + "  " + hrs + "  " + min + "  " + sec;
    time_txt.text = counter;

currentYear wasn't defined in my last message.  this is a more efficient countdown timer that doesn't require repeated creation of new dates:
var today:Date = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var targetDate:Date = new Date(currentYear, 3, 5);
var targetTime = targetDate.getTime();
var startTime:Number = getTimer();
this.onEnterFrame = function() {
    timeLeft = targetTime-currentTime-getTimer()+startTime;
    if (timeLeft<0) {
        targetDate = new Date(currentYear+1, 3, 5);
        targetTime = targetDate.getTime();
        timeLeft = targetTime-currentTime;
        startTime = getTimer();
    timeLeft/=1000;
    var days:Number = Math.floor(timeLeft/(60*60*24));
    var hrs:Number = Math.floor((timeLeft-days*24*60*60)/(60*60));
    var min:Number = Math.floor((timeLeft-days*60*60*24-hrs*60*60)/60);
    var sec = Math.floor(timeLeft-days*60*60*24-hrs*60*60-min*60);
    time_txt.text = formatF(days)+"  "+formatF(hrs)+"  "+formatF(min)+"  "+formatF(sec);
function formatF(n:Number):String {
    var s:String = n.toString();
    while (s.length<2) {
        s = "0"+s;
    return s;

Similar Messages

  • I USED to see the airplay symbol on my ipad. I don't see it anymore what's wrong? My system is up to date, I reset my Apple TV and everything else I can think of. What am I missing? Please help!

    I USED to see the airplay symbol on my ipad. I don't see it anymore what's wrong? My system is up to date, I reset my Apple TV and everything else I can think of. What am I missing? Please help!

    Did you reboot the router too?

  • I have accidentally deleted my sync data by resetting my sync-key. Is there any way to recover it ?

    A couple of days ago, i was setting sync up on my new PC and I accidentally deleted my data by resetting my sync-key.
    How can I recover my previous data? Is there a way or an e-mail address i can contact to help me with this.
    Thanks and regards,
    Gabriel

    Sorry, when the Sync Key is reset for a Sync account the existing data on the Sync server is cleared.

  • Cookies reappear after removing all website data & Safari reset

    Os X Mavericks - Cookies reappear after removing all website data & Safari reset

    I just dragged the entire ~/Library/cookies folder to the trash and then rebooted and it seemed to solve the problem.

  • Stackedbarchart does not considering CSS if chart data is reset.

    I am setting the CSS for Stackedbarchart . initially chart perfectly showing CSS colors for bars . but if i refresh the data set (i am creating new data set which has changes in y values only and  setting it to chart), chart is not considering the css colors, its showing some random colors for each series.
    steps to reproduce .
    use any sample /Ensamble
    set a style for chart bar / series with CSS .
    recreate  the chart data  and reset the chart data using chart.setData()
    chart is assigning random colors.

    Pay $200 for something i don't use often is ridiculous. Perhaps I am better off borrowing a PC and converting it for those SSD storage.

  • Tether data keeps resetting

    I have an iPhone 5 with Sprint. I use the Personal Hotspot feature with a 2GB plan, so I want to monitor it carefully. I use the Cellular Usage feature in Settings>General>Usage>Cellular Usage to monitor the amount of "Tether data" that I'm using. Unfortunately, it keeps resetting itself to 0 rather randomly, without my clicking on "Reset Statistics." None of the other data amounts reset themselves, they seem rather accurate. So I have to go to the Sprint website to check my data usage.
    I can't seem to see if there's anything I'm doing, like a hard reset, that would cause this. It just seems crazily random.
    Any suggestions?

    Well, iOS 5.1.1 does not have any good features so i was avoiding to upgrade my iOS..
    Isnt there any solution with iOS 5.0.1.?

  • Safari annoyance - creation/modification dates are reset on downloads

    When downloading files (images for example) by dragging them from a Safari window to a Finder window/drive, the files' creation date and modification date is reset to the date/time it is downloaded; this also happens if you choose "Save Image" from the contextual menu.
    It seems the only way Safari will preserve the original creation date and modification date of downloads is by option clicking a hyperlink that points to the file. Anyone know if there is any other way?
    Power Mac G4 dual 867 Mirrored Drive Doors   Mac OS X (10.4.4)  

    Thanks to the sharp folks at macosxhints.com I discovered that file creation/mod dates are preserved by dragging image files to Safari's Downloads folder, so I guess it suffices for my needs...still, drag-and-drop to the Finder should do the same.
    Also you can paste the file's URL into the address bar and hit option-return, or option-double click the file's URL in the Activity window.

  • Date/time resets when battery runs out on E51

    Any ideeas how to solve the problem?

    There is a little auxilliary in the phone. This is the battery that keeps the clock going when the main battery is removed or flat.
    Usually the date/time resets when there is a fault with this auxilliary battery. You can get it replaced at your nearest Nokia Care Point.
    You can find your nearest Nokia Care Point at:
    For UK
    http://www.nokia.co.uk/A4228006
    For Europe:
    http://europe.nokia.com/A4388379
    For Asia-Pacific
    http://www.nokia-asia.com/A4416070
    Elsewhere:
    http://www.nokia.com select your country, go to the support section, then select repair. 

  • I did a clear data and reset on my ipod touch and upon restart it is frozen. How do I fix it?

    I did a clear data and reset on my ipod touch and upon restart it is frozen. How do I fix it? I have already done the ten second hold restart with the top button and bottom button, but it still freezes. What should I do?

    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    Finally, if the Restore doesn't work, let the battery drain completely.  Then recharge for at least an hour and Restore again.

  • HT201412 iPhone 3g Needs Date & Time Reset on Startup if Battery is Allowed to Drain | Cause? Fix?

    Hi,
    There is an issue with my iPhone 3g.  When the battery drains completely, after recharging and booting up, the date and time revert to December 31st 1999, wrong hour, etc.  The battery holds a solid charge and was recently replaced.  However, the time reset issue was present even before battery replacement. 
    Does this phone model have an internal button cell battery that keeps time, as in some digital cameras?
    Am wondering if this normal or if a malfunction, what is the the cause?  Everything else works as expected.
    The phone is running iOS 4.2.1, jailbroken and unlocked, modem firmware 06.15.00.  Unsure but probably UltraSnow was used to unlock it since GPS is no longer functional.
    I have a 3gs (also jailbroken and unlocked) that does not have this date/time reset issue.
    Please share known solutions.  Any help is much appreciated, thank you for your time.

    Discussion of jailbroken devices is not permitted here per the terms of use of these forums.

  • Global data getting reset when running under IIS?

    We have a scenario using IIS with an ASP.NET web service written in VB.NET. When a call to the web service is made, the web service calls a native dll (written in C, compiled using VS2010) using platform invoke, which in turn calls into our product API:
    VB.NET web service -> native library (p/invoke) -> native API ....
    Web service requests are successfully completed and the system runs without problem for hours. A trace of the native API shows it is being called by multiple processes and multiple threads within those processes.
    The main native API dll contains a static global variable used to detect whether it is the first time it has been called and run initialization logic if it is. This dll is itself linked to a second dll that contains a global variable used to detect if it is
    the first time it has been called.
    After some hours the trace shows that the native API is invoked by an existing process but that the initialization logic is being exercised again, even though the global variable was set to indicate not first time and is never reset.  One theory was that
    the first process has ended and a new process has started almost instantaneously using the same process ID. However this is not the case as existing thread IDs from the same process are seen to write to the trace again after the first time logic has executed
    for the second time, indicating the process has not restarted. The problem occurs regularly.
    It is as though the process's global data has been initialized again and malloc'ed memory freed while the processing is still running. Is there any way this is possible when running under IIS?
    There is an internal thread which waits on a blocking read of a named pipe (via ReadFile), and when the problem occurs, the ReadFile call ends with ERROR_NO_ACCESS, which appears to indicate the malloc'ed buffer is no longer valid, again implying something
    has happened to the memory allocated to the process.

    Suggestting you asking it on:
    http://forums.iis.net/

  • Data not reset after 3 days on new billing cycle!!!

    My data has STILL not been reset and I'm three days into this billing cycle.  This is very frustrating because, with four people in my family sharing data, I need to be able to track data.  When I called customer service, they said not to worry because they could see (on their end), that it had been reset and that we've only used a fraction of a Gigabyte on this new billing cycle.  I guess it just really bothers me that when I look it up (text DATA, app, website), they all say that we are almost to our 6G limit.  I need to be able to keep track of data without calling customer service and being put on hold for several minutes.  Is this a common problem and is there a way to resolve it? 

    I am equally frustrated, last month was my "first month" with the jet pack, got text message alert use 75% of data package had not even use 30%, after being on hold for several minutes I was told oh don't worry accident, system having problems, now 3 days into new month appears we have used more than 1/2 our allowance &amp; haven't even been on our phones or gotten any alerts re:usage. I was totally mislead on speed of the jet pack &amp; have gone to store &amp; called customer service. I have been a Verizon customer for 13+ years but customer appreciation isn't important to Verizon.

  • Just purchased I-Pad 2 but wont sync my I-tunes library. All opsystems up to date. Reset I-pad but no success. Apps and fotos do sync. Music sync is activated. Any suggestions? Thanks

    Just purchased I-Pad 2 but will not sync my I-Tunes library. Ops system are up to date.
    I did reset the I-pad and started all over. Apps and fotos do sync but not music libray.
    Did not experience such a dproblem with I-phones nor with I-Pad 1.
    Any suggestions?

    IOS: Syncing with iTunes
    http://support.apple.com/kb/HT1386
    Apple - Support - iPad - Syncing
    http://www.apple.com/support/ipad/syncing/
    ITunes: Syncing media content to your iOS devices
    http://support.apple.com/kb/ht1351
     Cheers, Tom

  • I got a virus and need to save my data before resetting mozilla thunderbird

    I tried to get my messages with my computer and the only messages coming through is a newsletter from Thalia - a german bookstore. I can get my mails with the iphone - but of course I need to use my laptop as well for the communication.
    Now - I want to save all the data - mails, attachments... and reset the mozilla - hoping that this will work.
    I appreciate your support

    I would recommend saving a copy of your profile; see https://support.mozilla.org/en-US/kb/profiles-tb
    copy the folder to an separate folder or external drive.
    Then you can reload or update TB. The new TB should still use the profile you had before, but at least you have a backup position.

  • "Erase data" vs "Reset all settings"... do both erase Restrictions?

    I would like to prevent my son from resetting his iPhone, thus erasing the Restrictions (General>Restrictions) I have set.
    I think that he can't use the Reset function (Settings>General>Reset) without knowing his iCloud password (which he does not know). 
    But what about the "Erase all data" function (Settings>General>Passcode Lock>Erase Data) when one enters a Passcode wrong 10 times?  Would that also erase the Restrictions?  And if so, is there anything to prevent that from being done? 
    It looks as if that feature can be turned off, so that 10 Passcode attempts does not erase the data, but there is nothing to prevent a person from going in and turning that feature back on. 
    Thanks!

    Note: If you lose or forget a restriction passcode, you will need to perform a factory restore to remove it.
    The above comes from here:
    http://support.apple.com/kb/HT4213
    However, performing a factory restore would turning off Find My iPhone on the device, which disables Activation Lock.  This is described here:
    http://support.apple.com/kb/HT1414
    But ... turning off Find My iPhone requires the Apple ID and password, which you say is not available!
    So, you're safe!!

Maybe you are looking for