0

I'm working with a windows 8 app using Java Script

I'm get some rss and convert it to JSON format objects using Google API. So Then I got some sort of object array of JSON for that rss feed. I need to do is I want to select few objects among all objects of the array according to the published day. That means I want to get all objects from the array which published before 6 hours(In between current date and before 6 hours except other objects).. Can anyone help me for do that..?

I use this code for get all objects.

function loadNews() {
var allEntries = [];   
var pendingRequestCount = listOfFeed.length;
var onRequestFinished = function () {
    pendingRequestCount--;
    if (pendingRequestCount === 0) {
        processItems(allEntries);           
    }
};

for (var x = 0; x < listOfFeed.length; x++) {

        feedburnerUrl = listOfFeed[x].url,
            feedUrl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&output=json&num=999&q=" + encodeURIComponent(feedburnerUrl);
        WinJS.xhr({
            url: feedUrl,
            responseType: "rss/json"
        }).done(function complete(result) {
            var jsonData = JSON.parse(result.response);
            var entries = jsonData.responseData.feed.entries;
            allEntries = allEntries.concat(entries);

            allEntries.sort(function (entry1, entry2) {// Compare the entries by publish date
                return Date.parse(entry2.publishedDate) - Date.parse(entry1.publishedDate); // return get milisecond
            });
            onRequestFinished();
        });
    }  //loop x finish}

}

According to the above cord, allEntries provide JSON object array

Very thankful for the your answers

4

1 に答える 1

0

すべてのエントリをループして日付を比較する必要があります。テストに合格した日付ごとに、それを別の配列に追加します。例えば

var newEntries = JSON.parse(result.response),
    filteredEntries = [],
    i,
    testDate = new Date();

testDate = testDate.setHours(testDate.getHours() - 6);

for(i = 0; i < newEntries.length; i++) {
    if(newEntries[i].publishedDate > testDate) {
        filteredEntries.push(newEntries[i]);
    }
}

new Date()常に現在の日付を返す

Date.getHours()日付の時間部分を返します

Date.setHours(hour)日付の時間コンポーネントを設定します

が負の値の場合hour、日付は前日に移動します。たとえば、日付がコンポーネントをに2013-5-3 04:33設定していた場合、日付は次のように変更されますhour-22013-5-2 22:33

上記の例では、時刻が午前 2 時 45 分である場合、時刻コンポーネントが -4 に設定され、前日の午後 8 時 45 分に対してテストされます。

于 2013-10-09T03:23:43.837 に答える