jsのDate()時間の対象

3247 ワード

 var nowDate = new Date();
    nowDate.getYear(); //      (2 )
    nowDate.getFullYear(); //       (4 ,1970-????)
    nowDate.getMonth(); //      (0-11,0  1 )
    nowDate.getDate(); //     (1-31)
    nowDate.getDay(); //      X(0-6,0     )
    nowDate.getTime(); //      ( 1970.1.1      )
    nowDate.getHours(); //       (0-23)
    nowDate.getMinutes(); //       (0-59)
    nowDate.getSeconds(); //      (0-59)
    nowDate.getMilliseconds(); //       (0-999)
    nowDate.toLocaleDateString(); //      
    var myTime=nowDate.toLocaleTimeString(); //      
    var myDate=nowDate.toLocaleString( ); //       
    console.log(myTime);
    console.log(myDate);
 例:nを取った後は何曜日ですか?
var dateweek=document.getElementsByClassName("date-week")[0];
            var n=1000;//  
            
            var nowtimes=new Date();//        
            var t=nowtimes.getTime();//         
            
            var wt=t+1000*60*60*24*n;//1000      
            var c=new Date(wt)//1000      
            console.log(t)//   
            console.log(c)//    
            
            dateweek.innerHTML="  "+c.getDay();
 
転載先:https://www.cnblogs.com/xiaobaibubai/p/7060343.html