[Solved] Javascript check time difference


I’m not sure to understand what you want, but if you want to find out how long the button was pressed, there is how to do it.

var btn = document.getElementById('btn');
var timeStamp = Date.now();

btn.addEventListener('mousedown', function(){
    timeStamp = Date.now();
});
btn.addEventListener('click', function(){
    var t = Date.now() - timeStamp;
    /*You could add a condition to check the time here.*/
    document.getElementById('mssg').innerHTML = 
        "Mouse was hold " + t + " ms !";
});
<input type="button" id="btn" value="Click and hold" />
<span id="mssg"></span>

Else, if you want to make something happend after a certain amount of time, here is how to do that :

var btn = document.getElementById('btn');
btn.onclick = function(){
    alert('Hello !');
};
var remainingSeconds = 5;
var interval = setInterval(function(){
    remainingSeconds--;
    if(remainingSeconds > 0){
        btn.value="Wait (" + remainingSeconds + ' sec left)';
    }
    else{
        clearInterval(interval);
        btn.disabled = false;
        btn.value="You can now click";
    }
}, 1000);
<input type="button" id="btn" value="Wait" disabled>

I hope, I could help ! Please be more precise in your questions in the future !

solved Javascript check time difference