Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 按日期筛选对象数组_Jquery_Arrays_Date - Fatal编程技术网

Jquery 按日期筛选对象数组

Jquery 按日期筛选对象数组,jquery,arrays,date,Jquery,Arrays,Date,我有一个数组 0: Object end: "11-24-2014" index: 0 start: "11-21-2014" 1: Object end: "12-1-2014" index: 1 start: "11-28-2014 我需要得到当前日期在开始和结束之间的元素索引 有什么帮助吗??感谢循环将日期字符串转换为日期的数组,并查看当前日期是否介于两者之间 var index = check(arry); if (index >= 0) aler

我有一个数组

0: Object
  end: "11-24-2014"
  index: 0
  start: "11-21-2014"
1: Object
  end: "12-1-2014"
  index: 1
  start: "11-28-2014
我需要得到当前日期在开始和结束之间的元素索引


有什么帮助吗??感谢

循环将日期字符串转换为日期的数组,并查看当前日期是否介于两者之间

var index = check(arry);
if (index >= 0)
    alert("found @ " + index);


function check(arry) {
    var now = new Date();
    now.setHours(0, 0, 0, 0);

    for (var i = 0; i < arry.length; i++)
        if (now >= toDate(arry[i].start) && now <= toDate(arry[i].end)) 
            return i;

    return -1;

    function toDate(str) {
        var d = str.split("-");
        return new Date(d[2], d[0] - 1, d[1]);
    }
}

你有没有试过?你在哪里卡住了?我不知道如何根据当前日期获取项目。开始日期和结束日期之间的当前日期。