<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel = "stylesheet" href = "../css/mystyle.css" type="text/css">
<script>
today = new Date();
function proc1(){
bir = new Date(2010, 4-1, 12);
ttime = today.getTime();
btime = bir.getTime();
console.log(ttime, btime);
times = ttime - btime;
res = times /1000 /60 /60 /24 /365;
console.log(res);
str = "오늘 : " + today.toLocaleDateString() + "<br>"
str += "태어난 날:" + bir.toLocaleDateString() + "<br>"
str += parseInt(Math.ceil(res)) + "경과 하였습니다"
document.querySelector('#result1').innerHTML = str;
}
function proc2(){
tomilli = today.getTime();
milli100 = 1000* 60* 60* 24* 100;
millisum = tomilli + milli100;
after100 = new Date(millisum);
res = after100.toLocaleDateString();
str = "오늘 : " + today.toLocaleDateString() + "<br>";
str += "100일 후 : " + after100.toLocaleDateString() + "<br>";
document.querySelector('#result2').innerHTML = str;
}
function proc3(){
datevalue = document.getElementById('pdate').value;
selDate = new Date(datevalue);
times = today.getTime() - selDate.getTime();
console.log("times=" + times);
if(times < 0) {
alert("선택 오류 입니다");
return false;
}
days = times /1000 /60 /60 /24;
console.log("days=" + days);
if(days > 7){
res = "교환불가능";
}else{
res = "교환가능";
}
str = "오늘 : " + today.toLocaleDateString() + "<br>";
str += "구입 날짜 : " + selDate.toLocaleDateString() + "<br>";
str += res ;
document.querySelector('#result3').innerHTML = str;
}
function proc4(){
chris = new Date("2021.12.25");
times = chris.getTime() - today.getTime();
days = parseInt(times /1000 /60 /60 /24);
str = "크리스마스 까지" + days + "일 남았습니다."
document.querySelector('#result4').innerHTML = str;
}
</script>
</head>
<body>
<div class = "box">
경과시간 구하기
getTime() - 리턴값은 millisec이다<br>
millisec를 1000으로 나누면 실제 초를 구할 수 있다.<br>
태어난날 로부터 현재까지 일 또는 년수 구하기
<br>
<button type = "button" onclick="proc1()">확인</button>
<div id = "result1"></div>
</div>
<div class = "box">
경과시간 구하기
100일 후의 날짜 구하기
getTime() - 리턴값은 millisec이다<br>
1일의 millisec -> 1000* 60* 60* 24<br>
a = 현재의 millisec + 100일 후의 millisec<br>
new Date(a)<br>
<br>
<button type = "button" onclick="proc2()">확인</button>
<div id = "result2"></div>
</div>
<div class = "box">
경과시간 구하기
선택한 날로부터 경과한 날 수 구하기
getTime() - 리턴값은 millisec이다<br>
7일 이상이면 교환반품 불가능 아니면 가능 <br>
<br>
<input type = "date" id = "pdate"><br>
<button type = "button" onclick="proc3()">확인</button>
<div id = "result3"></div>
</div>
<div class = "box">
경과시간 구하기 getTime() - 리턴값은 millisec이다<br>
크리스마스까지 남은 일수 구하기
크리스마스 millisec - 오늘의millisec한다<br>
7일 이상이면 교환반품 불가능 아니면 가능 <br>
<br>
<input type = "date" id = "pdate"><br>
<button type = "button" onclick="proc4()">확인</button>
<div id = "result4"></div>
</div>
</body>
</html>
