특정 날짜로부터 초단위 시간 카운트 하기
특정 시간부터 초단위 카운트 올리기
js
function SetCount(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}
SetCount(2007,7,18)//시작 시간 설정
var displaymessage1="아기가 태어난지"
var displaymessage2="가 지났습니다."
var countupwidth='350'//표시 너비
var countupheight='20px'
var countupbgcolor='lightblue'//배경색상
var opentags=' <small>'//글자체 설정
var closetags=' </small>'
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
function start_countup(){
if (document.layers)
document.countLayer.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
countup()
}
if (document.all||document.getElementById)
document.write(' <span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"> </span>')
window.onload=start_countup
function countup(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
paststring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(todaystring)-Date.parse(paststring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if (document.layers){
document.countLayer.document.countupnssub.document.write(opentags+displaymessage1+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+displaymessage2+closetags)
document.countLayer.document.countupnssub.document.close()
} else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+displaymessage1+dday+ " 일, "+dhour+" 시간, "+dmin+" 분, "+dsec+" 초 "+displaymessage2+closetags
setTimeout("countup()", 1000)
}
html
<layer id="countLayer"> </layer>
CodePen
See the Pen 특정 시간부터 초단위 카운트 올리기 by younghyeong ryu (@wangta69) on CodePen.