<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,
조회수: 5327 |