This script shows the passing time from the date you wish.

<html>
    <head>
        <title>Passing time</title>
 
        <script type="text/javascript">
            var from_date = "Dec 18, 2009 12:00:00"; // Set the date from which the passing time will be shown
 
            var d = new Date();
            var current_time = d.getTime();
 
            var from_time = Date.parse(from_date);
 
            var diference_in_milliseconds = current_time - from_time;
 
            var passed_days = diference_in_milliseconds/1000/60/60/24;
            passed_days = parseInt(passed_days.toString());
 
            rest_milliseconds = diference_in_milliseconds - passed_days*24*60*60*1000;
 
            var passed_hours = rest_milliseconds/1000/60/60;
            passed_hours = parseInt(passed_hours.toString());
 
            rest_milliseconds = rest_milliseconds - passed_hours*60*60*1000;
 
            var passed_minutes = rest_milliseconds/1000/60;
            passed_minutes = parseInt(passed_minutes.toString());
 
            rest_milliseconds = rest_milliseconds - passed_minutes*60*1000;
 
            var passed_seconds = rest_milliseconds/1000;
            passed_seconds = parseInt(passed_seconds.toString());
 
            var t; 
 
            function passing_time(){
                if(passed_seconds==60){
                    passed_minutes = passed_minutes + 1;
                    passed_seconds = 0;
                }
                if(passed_minutes==60){
                    passed_hours = passed_hours + 1;
                    passed_minutes = 0;
                }
                if(passed_hours==24){
                    passed_days = passed_days + 1;
                    passed_hours = 0;
                }
 
                document.getElementById("passing_time").innerHTML = passed_days+" days, "+passed_hours+" hours, "+passed_minutes+" minutes, "+passed_seconds+" seconds.";
                passed_seconds = passed_seconds + 1;
                t = setTimeout("passing_time()",1000);
            }
        </script>
</head>
 
<body>
    <div id="passing_time"></div>
</body>
 
<script>passing_time();</script>
 
</html>
Share

Leave a Reply

Info