1
A
回答
2
1)求無天的兩個日期之間。然後,
for(i=0;i<noofdays;i++)
{
//Find the next date
//add to the array
}
2
NSCalendarUnit
供應定義拍攝日期是標準化的護理日期&之間的步驟。
的iOS API 8,雨燕2.0
func generateDates(calendarUnit: NSCalendarUnit, startDate: NSDate, endDate: NSDate) -> [NSDate] {
let calendar = NSCalendar.currentCalendar()
let normalizedStartDate = calendar.startOfDayForDate(startDate)
let normalizedEndDate = calendar.startOfDayForDate(endDate)
var dates = [normalizedStartDate]
var currentDate = normalizedStartDate
repeat {
currentDate = calendar.dateByAddingUnit(calendarUnit, value: 1, toDate: currentDate, options: NSCalendarOptions.MatchNextTime)!
dates.append(currentDate)
} while !calendar.isDate(currentDate, inSameDayAsDate: normalizedEndDate)
return dates
}
+1
謝謝。我正在使用這個Objective-C版本來完成我的場景。 – kevinl
0
找到兩個NSDates之間的所有天:
- (void)cerateDaysArray{
_daysArray = [NSMutableArray new];
NSCalendar *calendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];
[calendar setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *startDate = [_minDate copy];
NSDateComponents *deltaDays = [NSDateComponents new];
[deltaDays setDay:1];
[_daysArray addObject:startDate];
while ([startDate compare:_maxDate] == NSOrderedAscending) {
startDate = [calendar dateByAddingComponents:deltaDays toDate:startDate options:0];
[_daysArray addObject:startDate];
}
}
相關問題
- 1. 如何獲取兩個日期之間的所有日期?
- 2. 獲取兩個日期在兩個日期之間的差異在幾個月和幾天在sql
- 3. 獲取兩個日期之間的所有天在SQL Server整天小時
- 4. R - 獲取兩個日期之間的所有日曆年份
- 5. 獲取兩個日期之間不包含年份的天數
- 6. 獲取vba中的2個日期之間的所有日期
- 7. 如何獲取JQuery中的兩個日期之間的天
- 8. 查詢獲取這兩個日期之間的所有日期的計數
- 9. 獲取java中兩個日期之間的天數
- 10. 如何獲取兩個日期之間的天數?
- 11. 獲取php中兩個日期之間的天數
- 12. 獲取ios中兩個日期之間的天數名稱?
- 13. 獲取Jekyll中兩個日期之間的天差
- 14. 如何獲取代碼數組中兩個日期之間的所有日期
- 15. 顯示兩個日期間的所有天(日期)在angularjs
- 16. 兩個日期之間的天差
- 17. 兩個日期之間的總天數
- 18. 兩個日期之間的所有日期,間隔30分鐘
- 19. 獲取使用日期選擇器的兩個日期之間的天數
- 20. 如何將兩個日期時間之間的天數分成幾天?
- 21. 獲取兩個日期之間的最大日期/時間
- 22. 獲取列表中的兩個日期時間之間的所有時間
- 23. 得到兩個日期之間的日期,按星期幾
- 24. 如何生成兩個日期之間的所有日期
- 25. NSDateComponents在兩個日期之間獲取日期的日期屬性不正確
- 26. 在C#中獲取兩個'DateTime之間的所有日期時間'
- 27. 獲取日期範圍之間的所有行與分日期
- 28. 如何獲得兩個日期之間的所有產品?
- 29. 獲取SQL兩個日期之間的日期列表
- 30. 使用javascript獲取兩個日期之間的日期列表
你是什麼意思日期,而不是天? – msgambel
可能重複[兩個NSDates之間的天數](http://stackoverflow.com/questions/4739483/number-of-days-between-two-nsdates) –
@JoshCaswell主題說:「不是天」他想要一個日期列表。 –