[PL]/Java Script
날자 관련 function예제
객과 함께.
2011. 5. 21. 22:00
function showDate() { //현재 날자에 대한 정보를 갖는 객체(메소드+속성) 만듬(생성) var todayDate = new Date(); alert("오늘은 : " + todayDate); }
function showDate01() { //현재 날자에 대한 정보를 갖는 객체(메소드+속성) 만듬(생성) var todayDate = new Date(); var y = todayDate.getYear(); var m = todayDate.getMonth() + 1; // 0 ~ 11 까지얻어옴. /* 1 2 3 4 5 6 7 8 9 10 11 12 <= 월 0 1 2 3 4 5 6 7 8 9 10 11 <= 얻어오는 값 */ var d = todayDate.getDate(); var s = todayDate.getDay(); // 일 ~ 토요일 얻어옴( value : int ) var str = ""; switch(s) { case 0: str = "일" ; break; case 1: str = "월" ; break; case 2: str = "화" ; break; case 3: str = "수" ; break; case 4: str = "목" ; break; case 5: str = "금" ; break; case 6: str = "토" ; break; } alert(y + "년"+ m+"월" + d + "일 " + str + "요일"); }
function showDate02() { var newDate = new Date(); var shour = newDate.getHours(); var smin = newDate.getMinutes(); var ssec = newDate.getSeconds(); var str = newDate.getHours() + "시" + newDate.getMinutes() + "분" + newDate.getSeconds() + "초"; document.write(str); alert(shour + "시" + smin + "분" + ssec + "초" ); } |