zoukankan      html  css  js  c++  java
  • js获取8个月前时间,1天前时间

    一、获取八个月前时间

    //获取8个月前时间
    //小于10的前面加0
    function p(s) {
        return s < 10 ? '0' + s: s;
    }
    
    function getEightMonth(){
        var myDate = new Date();
        var currentYear=myDate.getFullYear();
        var currentMonth=myDate.getMonth()+1;  
        var currentDate=myDate.getDate();
    
             //八个月前
             var eightY=0;
             var eightM=0;
             var eigthD=0;
    
        var daysInMonth = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
        isYears(currentYear);
             if(currentMonth==1){
    
          //8个月前
            eightY= currentYear-1;
            eightM=5;
            eightD=monthTime(eightM,currentDate);
     
             }else{
                //8个月前的时间
            if(currentMonth -8 < 1){
                eightY = currentYear-1;
                eightM = isZero(12+(currentMonth-8));
                isZero(eightM);
                isYears(eightM);
                eightD =monthTime(eightM,currentDate)
            }else{
                eightY = currentYear;
                eightM = isZero(currentMonth-8);
                isZero(eightM);
                isYears(eightM);
                eightD =monthTime(eightM,currentDate)
            }
     }
             
         function isYears(years){
             if(years%4 == 0 && years%100 != 0  || years%400 == 0 ){
                    daysInMonth[2]= 29;
                }
         }
         function monthTime(a,b){
             if(daysInMonth[a] < b){
                     lastDate =  daysInMonth[a]
                }else{
                     lastDate = b;                
                }
             return lastDate;
         } 
         
         function isZero(s){
             if(s ==0 ){
                 return s =12;
             }else{
                 return s;
             }
         }
        //八个月前
     var eightMonth=eightY+"-"+p(eightM)+"-"+p(eightD);
     return eightMonth;
    }

    二、获取一天后的日期

    //24小时后
    var dDate=new Date();
    function getOneDay(){
        var nextDate = new Date(dDate.getTime() + 24*60*60*1000);   
        var year = nextDate.getFullYear();
        
        var oldmonth = nextDate.getMonth();
        var finalOldMonth=Appendzero(oldmonth);
        var month = nextDate.getMonth()+1;
        var finalMonth=Appendzero(month);
        
        var strDate = nextDate.getDate(nextDate);
        var finalStrDate=Appendzero(strDate);
        var OneDay= year+'-'+finalMonth+'-'+finalStrDate;
        return OneDay;
    
    }
  • 相关阅读:
    Python中最常见的10个列表操作
    使用Mac的texturetool将图片转换为PVRTC格式
    Android、iOS复制到粘贴板
    Python
    Pytest 作业
    Jmeter系列(34)- 详解 Jmeter CLI 模式
    Jmeter系列(33)- Jmeter 分布式测试
    Jmeter系列(32)- 详解性能监控工具 nmon
    Jmeter系列(31)- 详解 ForEach控制器
    Jmeter系列(30)- 详解 Loop Controller 循环控制器
  • 原文地址:https://www.cnblogs.com/pheosia/p/10097706.html
Copyright © 2011-2022 走看看