var elem = document.querySelector(".test");
var start;
var end;
elem.addEventListener("mouseenter", function() {
start = +(new Date());
}, false);
elem.addEventListener("mouseleave", function() {
end = +(new Date());
var result = ((end - start) / 1000).toFixed(2) + " sec";
elem.innerHTML = result;
}, false);