Js 는 지 정 된 날짜 에 며칠, 몇 달, 몇 년 의 날 짜 를 더 합 니까?

function   DateAdd(interval,number,date)
{
/*
  *     :  VBScript DateAdd  .
  *     :interval,      ,          .
  *     :number,     ,             .
  *     :date,    .
  *     :      .
  *   var   now   =   new   Date();
  *   var   newDate   =   DateAdd( "d ",5,now);
  *---------------   DateAdd(interval,number,date)   -----------------
  */
        switch(interval)
        {
                case   "y "   :   {
                        date.setFullYear(date.getFullYear()+number);
                        return   date;
                        break;
                }
                case   "q "   :   {
                        date.setMonth(date.getMonth()+number*3);
                        return   date;
                        break;
                }
                case   "m "   :   {
                        date.setMonth(date.getMonth()+number);
                        return   date;
                        break;
                }
                case   "w "   :   {
                        date.setDate(date.getDate()+number*7);
                        return   date;
                        break;
                }
                case   "d "   :   {
                        date.setDate(date.getDate()+number);
                        return   date;
                        break;
                }
                case   "h "   :   {
                        date.setHours(date.getHours()+number);
                        return   date;
                        break;
                }
                case   "m "   :   {
                        date.setMinutes(date.getMinutes()+number);
                        return   date;
                        break;
                }
                case   "s "   :   {
                        date.setSeconds(date.getSeconds()+number);
                        return   date;
                        break;
                }
                default   :   {
                        date.setDate(d.getDate()+number);
                        return   date;
                        break;
                }
        }
}

var   now   =   new   Date();
//   .
var   newDate   =   DateAdd( "d ",5,now);
alert(newDate.toLocaleDateString())
//    .
newDate   =   DateAdd( "m ",2,now);
alert(newDate.toLocaleDateString())
//   
newDate   =   DateAdd( "y ",1,now);
alert(newDate.toLocaleDateString()) 

좋은 웹페이지 즐겨찾기