테스트 사이트 - 개발 중인 베타 버전입니다

현재시간 초단위 채택완료

코프 6년 전 조회 15,248

안녕하세요. 아래처럼 시간을 나오게 하고 싶습니다.

 

초가 계속 카운트 되면서요...

 

초가 바뀌면서 페이지에서 보여지는걸 어떻게 해야하나여?

 

https://search.naver.com/search.naver?where=nexearch&query=%ED%98%84%EC%9E%AC%EC%8B%9C%EA%B0%84+%EC%B4%88%EB%8B%A8%EC%9C%84&ie=utf8&sm=tab_she&qdt=0">https://search.naver.com/search.naver?where=nexearch&query=%ED%98%84%EC%9E%AC%EC%8B%9C%EA%B0%84+%EC%B4%88%EB%8B%A8%EC%9C%84&ie=utf8&sm=tab_she&qdt=0

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
B
6년 전
로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

코프
6년 전
감사합니다.
코프
6년 전
아..그런데 일자 시 분 초 형식으로 나오게 하고 싶은데.

댓글을 작성하려면 로그인이 필요합니다.

이걸 빼먹었네요

<body>에 onload="startTime()" 추가해주세요~

완성 코드는 아래와 같습니다.

 

http://cloud.wckorea.gethompy.com/222.php">http://cloud.wckorea.gethompy.com/222.php

 

</p>

<p><body onload="startTime()"></p>

<p><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>

<?php

    $today = date("Y.m.d");

?></p>

<p>

<?php echo $today; ?> <span id="time"></span></p>

<p></body></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

아래와 같이 적용해보세요.
초단위는 실시간 으로 처리됩니다.

 

<!-- 시간/분/초 -->

<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></p>

<p><!-- 시간/분/초 --></p>

<p><!-- 현재날짜 -->

<?php

    $today = date("Y.m.d");

    $todays = explode('.',$today);

    $year = $todays[0]; //년도

    $month = $todays[1];//달

    $day = $todays[2];//일

?>

<!-- 현재날짜 --></p>

<p>

 

 

출력 하고자 하는 자리에 

 

</p>

<p><?php echo $today; ?> <span id="time"></span></p>

<p>// $today 년.월.일 출력,  id="time" 시간:분:초 출력</p>

<p>

 

 

예시 출력화면

 

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 3개

펄스나인
6년 전
엇 채택이 된 질문글이었네요 ㅎㅎ
코프
6년 전
댓글 감사합니다. 그런데 제대로 작동이 안되고 있습니다.ㅎ
알려주신대로 해보았으나 초가 바뀌질 않습니다. 윗분처럼 초가 변경되는게 보여야하는데..
코프
6년 전
했는데도 동일합니다.ㅠㅠ

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인