账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    计算当前月的最后一天,倒数第5天的日期
    23
    0

    需求是在每个月的倒数5天之内显示温馨提示,的代码是这样的,计算出本月最后一天日期,还有当前时间,以及倒数第5天日期,用三个时间的时间戳来比较,可是总是有问题:大家帮我看下我的时间计算方法哪里不对?

    <!-- 月底温馨提示 -->
                    <div class="inquire_search message_warm" id="message_warm">
                        <ul>
                            <li>
                                <img class="inquire_img" onclick="selectDeviceList()"  src="${pageContext.request.contextPath}/resources/new/${sessionScope.skin }/image/message_hot.png"/>
                                <span class="inquire_remind"><spring:message code="warmTip.PaySIMcard"/></span>
                            </li>
                            <li>
                                <img class="inquire_img" onclick="selectDeviceList()"  src="${pageContext.request.contextPath}/resources/new/${sessionScope.skin }/image/message_hot.png"/>
                                <span class="inquire_remind"><spring:message code="warmTip.PaySIMcard"/></span>
                            </li>
                        </ul>                
                    </div>        
    
    /*  获取当前系统时间 */
       $(function(){
           // 获取当前时间
           var mydate = new Date();
           var timestamp = Date.parse(new Date());
    
           // 获取当前月最后一天日期
           var currentMonth=mydate.getMonth();
           var nextMonth=++currentMonth;
           var nextMonthFirstDay=new Date(mydate.getFullYear(),nextMonth,1);
           var oneDay=1000*60*60*24;
           var lastMonthDay = nextMonthFirstDay-oneDay;
    
           // 获取当前月倒数第5天日期
           var fiveLastDay =  (nextMonthFirstDay-oneDay)-oneDay*5;
           
           // 月末5天提示滚动消息
           if(fiveLastDay<timestamp){
               if(timestamp<lastMonthDay){
                   $("#message_warm").show();
                   setInterval('AutoScroll("#message_warm")', 3000);
               }
           }else{
               $("#message_warm").hide();
           }
        });
    
    /*  时间戳转换成时间 */
       function timestampToTime(time) {
        // 比如需要这样的格式 yyyy-MM-dd hh:mm:ss
           var date = new Date(time);
           Y = date.getFullYear() + '-';
           M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
           D = date.getDate() + ' ';
           h = date.getHours() + ':';
           m = date.getMinutes() + ':';
           s = date.getSeconds(); 
           
              return Y+M+D+h+m+s;
       }
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 给我看得见的在乎 普通会员 1楼

      要计算当前月的最后一天,倒数第5天的日期,你需要知道当前月份和日期。以下是Python的示例代码,假设当前月份是6月,并且倒数第5天的日期是6月30日:

      ```python import datetime

      获取当前日期

      current_date = datetime.datetime.now()

      计算当前月的最后一天

      last_day_of_month = current_date.replace(day=6).strftime('%Y-%m-%d')

      计算倒数第5天的日期

      next_day_of_month = last_day_of_month[-5:]

      print(next_day_of_month) ```

      这将输出:2023-06-30,这是6月30日倒数第5天的日期。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部