2011-02-01 69 views
0

我有這樣的代碼:這個日期爲什麼處理不正確?

currentMinuteInt = [[cal components:NSHourCalendarUnit 
          fromDate:tuesdayAlarmTime] minute]; 

本應輸出 '15',而是 '輸出-2147483587'。我認識到這種奇怪的數字有時與日期相關,但我無法弄清楚它爲什麼會在這裏發生。

代碼中,我有工作了一小時是:

hours = [[cal components:NSHourCalendarUnit fromDate:now] hour]; 

和正常工作。 taysdayAlarmTime是一個完整的日期,它的一小部分是'15'。

回答

2

它不應該是

currentMinuteInt = [[cal components:NSMinuteCalendarUnit fromDate:tuesdayAlarmTime] minute]; 
+0

是的,就是這樣。不能相信我錯過了這一點。 – Andrew 2011-02-01 14:30:31

1

隨着[cal components:NSHourCalendarUnit fromDate:tuesdayAlarmTime],你NSDateComponents對象僅包含一個小時值,沒有別的。相反,您必須使用:

[cal components:NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:tuesdayAlarmTime] 
相關問題