자바스크립트로 만든 시계

자바스크립트로 만든 시계 updated_at: 2023-03-28 08:21

시간(clock) 자바스크립트

js

function MakeArrayday(size) { 
  this.length = size; 
  for(var i = 1; i  <= size; i++) { 
    this[i] = ""; 
  } 
  return this; 
} 

function MakeArraymonth(size) { 
  this.length = size; 
  for(var i = 1; i  <= size; i++) { 
    this[i] = ""; 
  } 
  return this; 
} 

function funClock() { 
  var runTime = new Date(); 

  var years = runTime.getFullYear();
  var months = runTime.getMonth()+1;
  var days = runTime.getDate();


  var hours = runTime.getHours(); 
  var minutes = runTime.getMinutes(); 
  var seconds = runTime.getSeconds(); 

  if (hours >= 12) { 
    hours = hours - 12; 
  } 
  if (hours == 0) { 
    hours = 12; 
  } 
  if (minutes  <= 9) { 
    minutes = "0" + minutes; 
  } 
  if (seconds  <= 9) { 
    seconds = "0" + seconds; 
  } 
  movingtime =  years+ "/" + months + "/" + days + "  " + hours + ":" + minutes + ":" + seconds ; 

  document.getElementById('clock').innerHTML = movingtime;

  setTimeout("funClock()", 1000) 
} 

window.onload = funClock; 

html

<span id=clock> </span>

CodePen

See the Pen javascript로 만든 clock by younghyeong ryu (@wangta69) on CodePen.

Table of contents 목차

평점을 남겨주세요
평점 : 5.0
총 투표수 : 1

질문 및 답글