test > BASIC_ORIGINAL

본문 바로가기

사이트 내 전체검색

뒤로가기 BASIC_ORIGINAL

페이지 정보

작성자 최고관리자 작성일 23-04-08 02:00 조회 545 댓글 0
기관명 test
대표
연락처
웹주소
업종
주소
사진
기관 소개내용
질문: how to make digital clock using javascript and show me an example.



Here is an example of how to make a digital clock using JavaScript:

[code]<script type="text/javascript">

// Get the current date
var date = new Date();

// Get the current hour
var hour = date.getHours();

// Get the current minute
var min = date.getMinutes();

// Get the current seconds
var sec = date.getSeconds();

// Format the minutes and seconds
if (min < 10) {
  min = '0' + min;
}

if (sec < 10) {
  sec = '0' + sec;
}

// Set up the clock string
var clock_string = hour + ':' + min + ':' + sec;

// Set the clock to the value of the clock string
document.getElementById('clock').innerHTML = clock_string;

// Update the clock every 1 second
setInterval(updateClock, 1000);

// Update the clock
function updateClock() {
  // Get the current date
  var date = new Date();

  // Get the current hour
  var hour = date.getHours();

  // Get the current minute
  var min = date.getMinutes();

  // Get the current seconds
  var sec = date.getSeconds();

  // Format the minutes and seconds
  if (min < 10) {
    min = '0' + min;
  }
  if (sec < 10) {
    sec = '0' + sec;
  }

  // Set up the clock string
  var clock_string = hour + ':' + min + ':' + sec;

  // Set the clock to the value of the clock string
  document.getElementById('clock').innerHTML = clock_string;
}

</script>

<p id="clock"></p>[/code]
찾아오는길

댓글목록 0

등록된 댓글이 없습니다.


로또번호 만들기

Copyright © EGIS.KR All rights reserved.

사이트 정보

Kim's Company / CEO : Kimchulyong
Contact : kimchulyong100@gmail.com

PC 버전으로 보기