美文网首页
根据生产日期 和 保质期天数得到过期时间

根据生产日期 和 保质期天数得到过期时间

作者: ___大鱼___ | 来源:发表于2018-11-05 11:07 被阅读1次
        // 保质期天数
        var ShelfLife = $('#ShelfLife').val();
        // 生产日期
        var ProductionDate = $('#ProductionDate').val();
        // 将日期格式的-替换为/
        var beginDate = new Date(Date.parse(ProductionDate.replace(/-/g, '/')));
        // 计算生产日期 和 保质期天数得到过期时间
        var date1 = Date.parse(ProductionDate.replace(/-/g, '/'))  + Number(ShelfLife) * 24 * 60 * 60 * 1000
         Date.prototype.format= function (fmt) { // author: meizz
              var o = {
                "M+": this.getMonth() + 1, // 月份
                "d+": this.getDate(), // 日
                "h+": this.getHours(), // 小时
                "m+": this.getMinutes(), // 分
                "s+": this.getSeconds(), // 秒
                "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
                "S": this.getMilliseconds() // 毫秒
              };
              if (/(y+)/.test(fmt))
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
              for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
              return fmt;
         };
        // 将过期时间格式化日期格式
        commonTime = new Date( date1 ) .format('yyyy-MM-dd');
         alert(commonTime);

相关文章

网友评论

      本文标题:根据生产日期 和 保质期天数得到过期时间

      本文链接:https://www.haomeiwen.com/subject/zdnjxqtx.html