私は、現在の日、週、または月に基づいてタスクを表示するタスク管理ウィジェットを作成しています。私はweeklyTaskArray、dailyTaskArray、monthlyTaskArrayに日付をプッシュし、それらを.lengthを使ってレンダリングしたいと思います。JSONオブジェクトの日付とangularjを使用した "5/17/16"形式の日付を比較するにはどうすればよいですか?
これは私が試したものですし、ステートメントの実行「であれば」しかしdailyQuoteArray/weeklyQuoteArrayなどにすべてのデータをプッシュ:
$http({
method: 'GET',
url: 'http://localhost:3000/api/quotes.json',
responseType: "json"
}).then(function(response) {
let quotes = response.data;
angular.copy(quotes, quoteArray)
quotes.forEach(function (element) {
let currentDate = element.expiration_date;
console.log(currentDate);
var moment = require('moment')
var todaysDate = moment("05/17/2016");
var date2 = moment(currentDate)
var answer = moment(todaysDate).diff(date2, "days")
console.log("this is the answer", answer);
if (answer >= 2) {
dailyQuoteArray.push(answer)
}
if (answer <= 7) {
weeklyQuoteArray.push(answer)
console.log("weeklyquotear length", weeklyQuoteArray.length);
}
})
});
を作成するには、 'として、ISOの日付を返すために、JSONのエンドポイントを変更することができます "2016-08-24T18:47:17.000Zを"'? – styfle