서버시간을 사용한 전자시계 > 개발자팁

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

서버시간을 사용한 전자시계 정보

JavaScript 서버시간을 사용한 전자시계

본문

<script> 
var now = new Date(<?php echo time(); ?>*1000);
Number.prototype.zf = function(){return (this > 9 ? '' : '0') + this;}; 
function startTime() { 
now.setSeconds(now.getSeconds() + 1);
        var h = now.getHours().zf(), m = now.getMinutes().zf(), s = now.getSeconds().zf();
        document.getElementById('time').innerHTML = h + ':' + m + ':' + s;
setTimeout('startTime()',1000);
}
</script> 
<body onload="startTime()"> 
<div id="time"></div>
추천
2
  • 복사

댓글 2개

© SIRSOFT
현재 페이지 제일 처음으로