zoukankan      html  css  js  c++  java
  • 日期的计算方法

                   // 处理日期算法 dateTemp 为日期时间  days为天数  天数加上日期时间的计算方法
                   getNewData(dateTemp, days) {  
                   var dateTemp = dateTemp.split("-");  
                   var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]); //转换为MM-DD-YYYY格式    
                   var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);  
                   var rDate = new Date(millSeconds);  
                   var year = rDate.getFullYear();  
                   var month = rDate.getMonth() + 1;  
                   if (month < 10) month = "0" + month;  
                   var date = rDate.getDate();  
                   if (date < 10) date = "0" + date;  
                   return (year + "-" + month + "-" + date);  
                },

    以下为实际调用写法 可供参考

                   // 处理日期算法
                   getNewData(dateTemp, days) {  
                   var dateTemp = dateTemp.split("-");  
                   var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]); //转换为MM-DD-YYYY格式    
                   var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);  
                   var rDate = new Date(millSeconds);  
                   var year = rDate.getFullYear();  
                   var month = rDate.getMonth() + 1;  
                   if (month < 10) month = "0" + month;  
                   var date = rDate.getDate();  
                   if (date < 10) date = "0" + date;  
                   return (year + "-" + month + "-" + date);  
                },
                // 报停开始
                bindConfirm_start(e) {
                    console.log(e,"这里");
                    this.starting_time = e.key;
                    if(this.value && this.starting_time){
                        this.getNewData(this.starting_time,this.value)
                        // console.log(this.getNewData(this.starting_time,this.value)) 报停结束时间等于报停开始时间加上报停天数
    this.end_time=this.getNewData(this.starting_time,this.value) } this.is_show++ },

     两个日期之间的运算

                 // date1 2020-10-15 date2 2020-10-10
                 GetNumberOfDays(date1,date2){//获得天数
                    //date1:开始日期,date2结束日期
                    var a1 = Date.parse(new Date(date1));
                    var a2 = Date.parse(new Date(date2));
                    var day = parseInt((date2-date1)/ (1000 * 60 * 60 * 24));//核心:时间戳相减,然后除以天数
                    return day
                },

    调用函数  输出天数

     onLoad() {
                uni.startPullDownRefresh();
                this.pendingList()
                this.GetNumberOfDays(2020-10-15,2020-10-10)
                console.log(this.GetNumberOfDays(2020-10-15,2020-10-10)) //5
            },
  • 相关阅读:
    November 13th 2016 Week 47th Sunday The 1st Day
    November 12th 2016 Week 46th Saturday
    November 11th 2016 Week 46th Friday
    November 10th 2016 Week 46th Thursday
    November 9th 2016 Week 46th Wednesday
    November 8th 2016 Week 46th Tuesday
    windows 7文件共享方法
    Win7无线网络共享设置方法
    常量指针和指针常量
    如何查找局域网的外网ip
  • 原文地址:https://www.cnblogs.com/lilamisu/p/13737641.html
Copyright © 2011-2022 走看看