Total members 10262 | Gratitudes |It is currently Wed May 23, 2012 8:32 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Time countdown
PostPosted: Mon Sep 05, 2011 11:04 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

This is example countdown for time , there is a loop you can remove it to make counter works just one time.
Code:

<html>
<
script language="javascript">
         
    function counter
(){  
        
// End date of counter down. divide by 1000 to get difference in seconds.
        var expireDate = parseInt(Date.parse("Sep 14, 2014")/1000);  
     
        
// Getting the current date.
        var now = new Date();  
        var current 
= parseInt(now.getTime()/1000);  
        var secDifference 
= expireDate - current;  
      
        
//Number of years left to expiration  .
        var yearsDifference = parseInt(secDifference/(60*60*24*365))  
        secDifference 
-= yearsDifference * 60 * 60 * 24 * 365;  
      
        
//Number of days left  to expiration .
        var daysDifference = parseInt(secDifference/(60*60*24));  
        secDifference 
-= daysDifference * 60 * 60 * 24;  
          
        
//Number of hours left  to expiration .
        var hoursDifference = parseInt(secDifference/(60*60));  
        secDifference 
-= hoursDifference * 60 * 60;  
      
        
//Number of minutes left  to expiration .
        var minutesDifference = parseInt(secDifference/(60));  
        secDifference 
-= minutesDifference * 60;  
         
        document
.getElementById("years").innerHTML=yearsDifference; 
        document
.getElementById("days").innerHTML=daysDifference;  
        document
.getElementById("hours").innerHTML=hoursDifference;  
        document
.getElementById("minutes").innerHTML=minutesDifference;  
        document
.getElementById("seconds").innerHTML=secDifference; 
    
}  
</script>
    
<body>  
  <table border="1">  
     <tr>  
      <th>Years</th>  
      <th>  </th>  
      <th>Days</th>  
      <th>  </th>  
      <th>Hours</th>  
      <th>  </th>  
      <th>Minutes</th>  
      <th>  </th>  
      <th>Seconds</th>  
     </tr>  
     <tr>  
      <td align="center"><span id="years"></span></td>  
      <td>:</td>  
      <td align="center"><span id="days"> </span></td>  
      <td>:</td>  
      <td align="center"><span id="hours"> </span></td>  
      <td>:</td>  
      <td align="center"><span id="minutes"> </span></td>  
      <td>:</td>  
      <td align="center"><span id="seconds">  </span></td>  
     </tr>  
    </table>  
    <script language="javascript">
    while(true){
     sleep(100)
    
     counter();
    }
    function sleep(delay)
    {
    var startTime = new Date().getTime();
    setTimeout(counter, 1000) 
    }
    
    </script>
    </body>
</html>

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Plz Help,I want BOTH THREAD to work at a time in SAME WINDOW
 Selecting a Domain Name at the Time of Registration
 login using sessionid or time
 redirect after countdown
 Having a hard time with this class need help deseperately.
 calculate the load time for a page
 current system time
 Java Websphere Portal Developer Full-time position in IL
 Part Time Online Jobs
 First Name:raju visa process time

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team