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 :
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 :