js获取当前时间

 var now = new Date();
             var year = now.getFullYear();       //年
                var month = now.getMonth() + 1;     //月
                if(month < 10){
                    month= "0"+month;
                    }
                var day = now.getDate();            //日
                if(day < 10){
                    day= "0"+day;
                    }
                
                var hour = now.getHours();            //小时
                if(hour < 10){
                    hour= "0"+hour;
                    }
                
                var minute = now.getMinutes();            //分钟
                if(minute < 10){
                    minute= "0"+minute;
                    }
         
            var date2=year+'-'+month+'-'+day+' '+hour+':'+minute+':00';    

js获取当前毫秒值

var timestamp = new Date().getTime();

js比较时间大小:可以直接比较

if(date2==date2){}

 js获取当前时间、js时间戳转日期

 //获取时间的方法、参数一为加几天、参数二 :1为年月日、2为年月日时分秒、3为时分------------------------------------------------------------------------------------
              function gettime(d,y){
                var tm= new Date().getTime();
                 var now = new Date(24*60*60*1000*d+tm);
                  var year = now.getFullYear();       //年
                     var month = now.getMonth() + 1;     //月
                     if(month < 10){
                         month= "0"+month;
                         }
                     var day= now.getDate();            //日
                     if(day < 10){
                         day= "0"+day;
                         }
                     
                     var hour = now.getHours();            //小时
                     if(hour < 10){
                         hour= "0"+hour;
                         }
                     
                     var minute = now.getMinutes();            //分钟
                     if(minute < 10){
                         minute= "0"+minute;
                         }
                        
                 if(y==1){
                      return year+'-'+month+'-'+day;
                      }else if(y==2){
                         return year+'-'+month+'-'+day+' '+hour+':'+minute+':00';    
                       }else if(y==3){
                            return ""+hour+minute;
                            }
                   }

 

上一篇:SQL查询时间间隔


下一篇:python--静态方法