0초 부터 초단위로 초올리기
0초 부터 초단위로 초올리기
js
startday = new Date();
clockStart = startday.getTime();
function initStopwatch() {
var myTime = new Date();
return((myTime.getTime() - clockStart)/1000);
}
function getSecs() {
console.log('getSecs start');
var tSecs = Math.round(initStopwatch());
var iSecs = tSecs % 60;
var iMins = Math.round((tSecs-30)/60);
var sSecs ="" + ((iSecs > 9) ? iSecs : "0" + iSecs);
var sMins ="" + ((iMins > 9) ? iMins : "0" + iMins);
var timeRemain = sMins+":"+sSecs;
document.getElementById('clock').innerHTML = timeRemain;
window.setTimeout('getSecs()',1000);
}
window.onload = window.setTimeout('getSecs()',1)
html
<span id="clock" class="txt_red"></span>
See the Pen 0초 부터 초단위로 초올리기 by younghyeong ryu (@wangta69) on CodePen.