2015-07-09 75 views
1
我使用在頁面 ng-show

我要創建:比較日期在Angularjs

<td ng-show="week.EndDate > controller.currentDate"> 

其中weekEndDatecurrentDate在我的控制器設置一個屬性的對象:

currentDate = new Date(); 

我的ng-show是否設置日期>,<或=失敗。我打印出來我的日期,這是它們是什麼:

week.Date = 2014年11月7日 controller.currentDate = 2015-07-09T21:54:40.655Z

我不知道,如果這個問題是由格式不同造成的。如果是的話,我該如何糾正這個問題,如果沒有的話,還有另一種比較日期的方法嗎?

+1

* currentDate *是一個Date對象,很可能* week.Date *是一個字符串。 – RobG

+0

創建一個過濾器 – ngLover

回答

1

您應該將您的week.EndDate字符串轉換爲Date對象,或者將您的比較包含在可將其轉換爲日期的函數中。

ng-show="convertToDate(week.EndDate) > controller.currentDate" 

你需要記住的唯一的事情是,當你轉換week.EndDate永久的Date對象,當你想在一些地方保存它,例如,你可能需要將其轉換回你想要的格式。