jsは年月日と年月日を取って加减します.

3871 ワード

もっと読む

   
    //  
    var myDate = new Date();  
    myDate.getYear();       //      (2 )  
    myDate.getFullYear();   //       (4 ,1970-????)  
    myDate.getMonth();      //      (0-11,0  1 )  
    myDate.getDate();       //     (1-31)  
    myDate.getDay();        //      X(0-6,0     )  
    myDate.getTime();       //      ( 1970.1.1      )  
    myDate.getHours();      //       (0-23)  
    myDate.getMinutes();    //       (0-59)  
    myDate.getSeconds();    //      (0-59)  
    myDate.getMilliseconds();   //       (0-999)  
    myDate.toLocaleDateString();    //        
    var mytime=myDate.toLocaleTimeString();    //        
    myDate.toLocaleString( );       //         
if (mytime<"23:30:00")  
{  
alert(mytime);  
}  
</pre> 
 <br> 
 <br> 
 <br> 
 <pre name="code" class="html">
 <script language="javascript">  
    //    
   function addDate(date,days){
    var d=new Date(date);
    d.setDate(d.getDate()+days);
    var m=d.getMonth()+1;
    return d.getFullYear()+'-'+m+'-'+d.getDate();
  }

   var dd="2014-02-28".split("-");
   var today = new Date(dd[0],dd[1]-1,dd[2]);
   document.write(addDate(today,1));
</pre> 
 <br> 
 <br> 
 <pre name="code" class="html">
 <script language="javascript">  
    //    
    Date.prototype.Format = function(fmt){
    //author: meizz 
    var o =
     { 
        "M+" : this.getMonth() + 1, //   
        "d+" : this.getDate(), //  
        "h+" : this.getHours(), //   
        "m+" : this.getMinutes(), //  
        "s+" : this.getSeconds(), //  
        "q+" : Math.floor((this.getMonth() + 3) / 3), //   
        "S" : this.getMilliseconds() //   
     }; 
    if (/(y+)/.test(fmt)) 
         fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 
    for (var k in o) 
        if (new RegExp("(" + k + ")").test(fmt)) 
             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); 
    return fmt; 
}

Date.prototype.addDays = function(d){
    this.setDate(this.getDate() + d);
};

Date.prototype.addWeeks = function(w){
    this.addDays(w * 7);
};

Date.prototype.addMonths= function(m){
    var d = this.getDate();
    this.setMonth(this.getMonth() + m);

    if (this.getDate() < d)
        this.setDate(0);
};


Date.prototype.addYears = function(y){
    var m = this.getMonth();
    this.setFullYear(this.getFullYear() + y);

    if (m < this.getMonth()) 
     {
        this.setDate(0);
     }
};

var dd="2014-4-04".split("-");
var today = new Date(dd[0],dd[1]-1,dd[2]);

today.addDays(27);//      
//document.write(today.getFullYear()+"-"+today.getMonth()+"-"+today.getDate());
document.write(today.Format("yyyy-MM-dd"));
</pre> 
 <br> 
 <br> 
 <br> 
 <span style="color: red;"><em>       </em></span> 
 <br> 
</div>
                            </div>
                        </div>
                    </div>
                    <!--PC WAP    -->
                    <div id="SOHUCS" sid="1176615778078765056"></div>
                    <script type="text/javascript" src="/views/front/js/chanyan.js">