2014年5月14日 星期三

如果只有開始跟結束的小時,要如何判斷是今日或昨日

NSCalendar *cal = [NSCalendar currentCalendar];
            NSDateComponents *sleepComps = [cal components:NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:se.sleepDate];
            NSDateComponents *wakeUpComps = [cal components:NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:se.wakeUpDate];
            date = [_displayDate startDayDate];
            if (sleepComps.hour > wakeUpComps.hour)

                date = [date dateByAddingTimeInterval:-86400];

沒有留言:

張貼留言