var today = new Date();//Data객체 참조
today.getYear() //년
today.getMonth()//월0~11월, +1해줘야 함.
today.getdate() //일
today.getDay()//요일0에서 6요일
today.getHours()//시
today.getMinutes()//분
today.getSeconds() //초
예제)
var dYoil = new Array('일', '월', '화', '수', '목', '금', '토');
var dToday = new Date();
//요일
var yoil = dToday.getDay();
//시간
var hour = dToday.getHours();
alert('오늘은 ' + dYoil[yoil] + ';;' + yoil + '요일입니다\n시간은' + hour + '시입니다');
예제2) -- 주말에만 팝업을 띄우자..
<script type="text/javascript" language="javascript">
function GetCookie(NameCookie) {
var i = document.cookie.indexOf(NameCookie + '=');
if (i != -1) {
i += NameCookie.length + 1;
NameEnd = document.cookie.indexOf(';', i);
if (NameEnd == -1) {
NameEnd = document.cookie.length;
}
return unescape(document.cookie.substring(i, NameEnd));
}
else {
return "";
}
}
function window.onload() {
var jumalYn = false;
var dToday = new Date();
var yoil = dToday.getDay();
var hour = dToday.getHours();
switch (yoil) {
case 0: jumalYn = true; break;
case 1: jumalYn = false; break;
case 2: jumalYn = false; break;
case 3: jumalYn = false; break;
case 4: jumalYn = false; break;
case 5: if (hour > 16) jumalYn = true; break;
case 6: jumalYn = true; break;
default: jumalYn = false; break;
}
if (jumalYn) {
var Cookievalue = GetCookie('Tourplanner');
if (Cookievalue == "") {
var tour = window.open('http://www.naver.com', 'weekend', 'width=400,height=325');
tour.focus();
}
}
}
</script>