TAG
CSS
JavaScript
Result
Run
License
<h1 class="title">Date.prototype.getTime() Method</h1> <h2>Current Time: <span class="curtime"></span></h2> <h2>Milliseconds : <span class="unixtime"></span><span></span></h2>
.title { border-bottom: 1px solid #CCC; padding-bottom: 10px; } .unixtime + span { color: #FF0000; position: relative; } .unixtime { position: relative; } .unixtime::before { content: "UNIXTIME"; background: #FFFF00; border-top: 2px dotted #FF0000; } .unixtime + span::before { content: "1/1000s"; background: #EAEAEA; border-top: 2px dotted #0000FF; } .unixtime::before, .unixtime + span::before { position: absolute; display: inline-block; bottom: -17px; left: 0; right: 0; font-size: 13px; text-align: center; padding-top: 3px; }
window.addEventListener("load", function() { if (timer1) clearTimeout(timer1); if (timer2) clearTimeout(timer2); var timer1, timer2; timer1 = setInterval(function() { var d = new Date(); document.querySelector(".curtime").textContent = d.toLocaleTimeString(); }, 1000); timer1 = setInterval(function() { var d = new Date(); var timeStr = String(d.getTime()); var unixtime = timeStr.substr(0, timeStr.length - 4); var millisec = timeStr.substr(-4); document.querySelector(".unixtime").textContent = unixtime; document.querySelector(".unixtime + span").textContent = millisec; }, 1); });
Console
expand_less
License
License
by DevDic
Close