最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Compare time in javascript - Stack Overflow

programmeradmin5浏览0评论

I need to create a function to filter data according to time.

I have a table of flights with departure time in related rows, what i need is, i will put to time filter fields to my form, for hiding flights before and after selected time. In other words, flighs bettween selected time interval will be visible.

I have no problem with getting time info from table and my inputs, but i do not now how to pare them. I use jquery.

I need to create a function to filter data according to time.

I have a table of flights with departure time in related rows, what i need is, i will put to time filter fields to my form, for hiding flights before and after selected time. In other words, flighs bettween selected time interval will be visible.

I have no problem with getting time info from table and my inputs, but i do not now how to pare them. I use jquery.

Share Improve this question edited Dec 25, 2014 at 10:39 Mp0int asked Jul 23, 2010 at 7:52 Mp0intMp0int 18.8k16 gold badges87 silver badges118 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 7

No need for jquery on this one. Just plain old javascript.

The easiest way is to just convert the date objects to unix time using getTime method (I think that is the name). Then just do a greater/less than parison to see if the values are within the range.

The easiest and fastest way of doing client side data manipulation (sorting, filtering, grouping) is jOrder.

In your case, I assume the data looks something like this: (date1 and date2 being date objects)

var data = [{flight: '776', departure: date1}, {flight: '51', departure: date2}];

First thing, create a jOrder table out of the array, with index on departure time.

var table = jOrder(data)
    .index('departure', ['departure'], {grouped: true, ordered: true});

Then, you can easily select the row with dates in the specified range.

 var hits = table.where([{ departure: {lower: datelow, upper: datehi}}], {mode: jOrder.range});

Finally you can rebuild or modify the UI objects according to the hits.

jOrder is available at http://github./danstocker/jorder.

发布评论

评论列表(0)

  1. 暂无评论