Friday, 31 August 2018

How to show the timer Control in mvc using Javascript

How to show the time Control in mvc using Javascript ?

Html code :
     <p id="demo"></p>
Javascript code :
<script>
        var countDownDate = new Date();
        countDownDate.getHours(); // => 9
        countDownDate.setMinutes(countDownDate.getMinutes() + 30); // =>  30 
        countDownDate.getSeconds(); // => 51     
     
            var x = setInterval(function() {
                var now = new Date().getTime();
                var distance = countDownDate - now;
                var minutes = Math.floor((distance % (1000 * 60*60)) / (1000 * 60));
                var seconds = Math.floor((distance % (1000 * 60)) / 1000);
                document.getElementById("demo").innerHTML =  minutes + " : " + seconds;
                if (seconds <= 0 && minutes <= 0) {
                    window.location.href = "../User/User_Login";
                    document.getElementById("demo").innerHTML = "EXPIRED";
                }
            }, 1000);
        }
    </script>

View :
   

No comments:

Post a Comment

Top Agile Interview Questions & Answers

Top Agile Interview Questions & Answers 1. What is Agile Testing? The first question of agile interview question tests your k...