列表中的截止日期的前三个月的日期跟当天日期进行比较,大于等于当天日期字体变红,否则黑色

本文介绍如何使用JavaScript实现列表中距截止日期前三个月的日期与当前日期比较,如果达到或超过当前日期,则字体显示为红色;否则,显示为黑色。主要涉及日期对象的操作和条件判断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需求: 列表中的截止日期的前三个月的日期跟当天日期进行比较,大于等于当天日期字体变红,否则黑色

效果图

在这里插入图片描述

    <template slot-scope="scope">
            <span class="timedateblock" v-if="scope.row.outTime">{{ scope.row.expirationDate }}</span>//判断outTime小于当天日期字体变黑,否则变红
            <span class="timedatered" v-else>{{ scope.row.expirationDate }}</span>
    </template>
------------------------------------------------------------------------------------------
async getlist() {
      let req = {
        page: this.page,
        limit: this.limit,
        parkId: this.parkId,
        industryType: this.industryType,
        enterpriseName: this.enterpriseName,
      };
      let list = await dossier.emengercyList(req);
      let res = list.page.list;
      ====================================================================================
      for (let i = 0; i < res.length; i++) {
        const element = res[i];
        element.outTime = true;
        if (element.expirationDate) {
          element.outTime = this.checkTime(element.expirationDate);
        }
      }
      =====================================================================================
      this.tableData = res;
      this.total = list.page.totalCount;
    },
    =======================================================================================
    checkTime(datetime) {
      let myDate = new Date(datetime);//列表中的日期
      let year = myDate.getFullYear();//获取年
      let lastM = myDate.getMonth() + 1;//获取月
      let lastD = myDate.getDate();//获取日
      if (lastM > 3) {//判断月份是否大于3
        lastM = lastM - 3;//月份大于3减去3个月
      } else {
        year = year - 1;//月份小于3 年份减去一 
        lastM = lastM + 12 - 3;//月份减去3
      }
      let startData = new Date(year + '-' + lastM + '-' + lastD + ' 00:00:00').getTime();//把年月日拼接
      let nowtime = new Date(parseTime(new Date(), '{y}-{m}-{d} 00:00:00')).getTime();//获取当前日期
      return Number(startData) > Number(nowtime);//进行比较
    },
    =======================================================================================
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值