首页 > 解决方案 > 我正在处理 django 上的日期,有没有办法比较 html 上的呈现日期以检查当前日期是否还剩不到 3 天

问题描述

我有这个代码,它通常显示数据库上的所有行数。有没有办法将返回的日期(承诺日期)与 javascript 或 jquery 进行比较,以便我可以突出显示距今天日期不到 3 天的所有日期。谢谢

<div class="container">
  <table id="requirement_table" class="table table-bordered table-hover table-sm" style="width:100%">
    <thead>
      <tr>
        <th>Applicant Name</th>
        <th>Requirement</th>
        <th>Remarks</th>
        <th>Promised Date</th>
        <th>Completed</th>
      </tr>
    </thead>

    <tbody>
      {% for req in app_requirements %}
      <tr>
        <th>{{ req.applicant }}</th>
        <th>{{ req.requirement }}</th>
        <th>{{ req.remarks }}</th>
        <th>{{ req.date_promised }}</th>
        <th>{{ req.completed }}</th>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</div>

标签: javascriptjquerydjango

解决方案


将字符串转换为日期对象并将其与您需要的日期进行比较。

let myDate = getDateSomewhere();
Date.parse(myDate);

推荐阅读