小编Suy*_*ant的帖子

对字符串日期数组排序

我想按升序对数组进行排序.日期是字符串格式

["09/06/2015", "25/06/2015", "22/06/2015", "25/07/2015", "18/05/2015"] 
Run Code Online (Sandbox Code Playgroud)

甚至需要一个函数来检查这些日期是否是连续的形式:

eg - Valid   - ["09/06/2015", "10/06/2015", "11/06/2015"] 
     Invalid - ["09/06/2015", "25/06/2015", "22/06/2015", "25/07/2015"] 
Run Code Online (Sandbox Code Playgroud)

示例代码:

function sequentialDates(dates){
        var temp_date_array = [];

        $.each(dates, function( index, date ) {
            //var date_flag = Date.parse(date);
            temp_date_array.push(date);
        });

        console.log(temp_date_array);

        var last;
        for (var i = 0, l = temp_date_array.length; i < l; i++) {

          var cur = new Date();
          cur.setTime(temp_date_array[i]);
          last = last || cur;
          //console.log(last+' '+cur);

          if (isNewSequence(cur, last)) {
            console.log("Not Sequence");
          }
        }

        //return dates;
    }

     function …
Run Code Online (Sandbox Code Playgroud)

javascript jquery datetime bootstrap-datepicker

10
推荐指数
2
解决办法
2万
查看次数