Jquery搜索日期

时间:2016-09-04 14:17:40

标签: jquery html

我尝试从目录树中按日期搜索。 但是日期在文件创建日期是文件名,我想在startDate和endDate之间进行搜索。

enter image description here

我的HTML:

<div class="row">
<div style="float:left; width:17%;">
    <input type="text" style="height:37px;" id="startDate" class="form-control" placeholder="DD/MM/YY">
</div> 
<div style="float:left; width:17%; margin:0 1%;">
    <div class="input-group">
    <input type="text" style="width:97.71px;" id="endDate" height:37px;" class="form-control" placeholder="DD/MM/YY" />
    <span class="input-group-btn">
        <button style="padding: 7.5px 12px; left:-1px;" class="btn btn-default" id="DateSearch" type="button"><i class="fa fa-search"></i></button>
    </span>
    </div>
</div>

Jquery的: 没弄明白怎么做。 我发现了一些datePickers,但我不想使用它们并找到dataTables。 我想通过文件创建日期在我的目录树中搜索文件名。

1 个答案:

答案 0 :(得分:1)

按我在评论中提到的方式拆分,以此格式制作year-month-date,并将每个文件日期与from - to范围进行比较

例如

<强> HTML

<p class="date">2013-08-4</p>
<p class="date">2014-09-5</p>
<p class="date">2015-09-5</p>
<p class="date">2016-09-5</p>

<强>代码

    $(function() {
  var from = new Date("2013-09-4").getTime();
  var to = new Date("2014-09-8").getTime();

  $(".date").each(function(index, value) {
    var dates = $(this).text();

    if (from <= new Date(dates).getTime() && to >= new Date(dates).getTime()) {

      $(this).css("color", "blue");

    }

  });

});

<强>输出

enter image description here

Demo

您可以使用strtotime($the_date);在PHP中执行相同操作,这会为您提供分钟

相关问题