푸른청년 푸르게 살고있나?  
home | 살아가기 | news | 세상보기 | tip&tech | 방명록 |  
   전체
   asp
   php
   jsp
   mssql
   mysql
   informix
   linux
   unix
   win2000
   javascript
   html
   oracle
   java
   etc
    
:: Tip&Tech > javascript
자바스크립트 현재날짜, 특정날짜, 며칠후날짜, 날짜사이 일수 등등
<script type="text/javascript">
var n,a,b,chki;
n = new Date();
n_year = n.getYear();
n_month = n.getMonth()+1;
n_day = n.getDate();

n_month = get2DateFormat(n_month);
n_day = get2DateFormat(n_day);
document.write('현재날짜 : '+n_year+'년 '+n_month+'월 '+n_day+'일<p>');


//특정날짜로 설정하기
a = new Date();
a.setYear(2007);
a.setMonth(4); //5월 - 1
a.setDate(14);


s = "7";
b = timeShift(a,s);
b_year = b.getYear();
b_month = b.getMonth()+1;
b_day = b.getDate();

b_month = get2DateFormat(b_month);
b_day = get2DateFormat(b_day);
document.write(s+'일후 : '+b_year+'년 '+b_month+'월 '+b_day+'일<p>');

chki = getDayInterval(a,n);
document.write( '5월 14일로부터 ' + chki + '일<p>' );


//함수들
function get2DateFormat(str){
if(str<10){
str = '0'+str;
}

return str;
}

//a : 기준시간, str : 몇일(+:몇일후,-:몇일전)
function timeShift(a,str){
b = new Date();
b.setTime(a.getTime() + ((str) * 24 * 60 * 60 * 1000));

return b
}

function getDayInterval(time1,time2) {
var date1 = time1;
var date2 = time2;
var day = 1000 * 3600 * 24; //24시간

return parseInt((date2 - date1) / day, 10);
}

</script>

날짜: 2007-05-14 11:16:55, 조회수: 5194

이전글 url에 따라 메뉴 바꾸기

꼬리말
글쓴이 비밀번호 #스팸글방지(주인장 닉네임을 쓰시오)

  
since by 2003.03.23 / 3th 2005.07.26 / 4th 2009.04.22 made by bluesoul