NSDateComponents를 사용하여 수요일과 금요일에 몇 가지 미래의 날짜를 얻는 방법? 답변은 크게 감사하겠습니다. 미리 감사드립니다.미래 날짜를 얻는 방법
-1
A
답변
3
완전히 총알 방지를 원한다면 실제로는 약간 까다로운 문제입니다. 여기에 내가 그것을 할 것입니다 방법은 다음과 같습니다 [? 당신이 시도 무엇]
NSInteger wednesday = 4; // Wed is the 4th day of the week (Sunday is 1)
NSInteger friday = 6;
NSDate *start = ...; // your starting date
NSDateComponents *components = [[NSDateComponents alloc] init];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
for (int i = 0; i < 100; ++i) {
[components setDay:i];
NSDate *target = [gregorian dateByAddingComponents:components toDate:start options:0];
NSDateComponents *targetComponents = [gregorian components:NSUIntegerMax fromDate:target];
if ([targetComponents weekday] == wednesday || [targetComponents weekday] == friday) {
NSLog(@"found wed/fri on %d-%d-%d", [targetComponents month], [targetComponents day], [targetComponents year]);
}
}
[gregorian release];
[components release];
+0
을 그것은! 작동합니다. 고마워. .. – isarathg
0
올바른 요일을 얻으려면 NSCalendar의 적절한 인스턴스를 만들고 dateFromComponents :를 사용하여 NSDate 개체를 만든 다음 components : fromDate :를 사용하여 요일을 검색해야합니다.
NSDate *yourDate = ...
NSDateComponents* components = [[NSDateComponents alloc] init];
components.week = weeks;
NSDate* futureDate = [[NSCalendar reCurrentCalendar] dateByAddingComponents:components toDate:yourDate options:0];
[components release];
추신 : 당신은 콘크리트 평일 NSDate
예 (f.e. 수요일)가있는 경우
0
, 당신은 다음과 같은 코드를 사용하여 새로운 미래 날짜를 얻을 수 있습니다 Brian과 동의하고, 묻기 전에 연구 해보십시오.
관련 문제
- 1. 상대 날짜를 얻는 방법
- 2. 사용자가 미래 날짜를 입력하거나 선택하지 못하도록 막으십시오.
- 3. Silverlight DatePicker 컨트롤에서 미래 날짜를 비활성화하려면 어떻게해야합니까?
- 4. 우리나라에서 정확한 날짜를 얻는 방법?
- 5. mdx에서 최신 날짜를 얻는 방법?
- 6. Android : Date Picker 현재 날짜와 미래 날짜를 받아 들여서는 안됩니다.
- 7. 날짜와 시간 속성에서 미래 이벤트를 얻는 가장 좋은 방법
- 8. 사용자 도메인의 만료 날짜를 얻는 방법
- 9. 반복없이 데이터베이스와 디스플레이에서 날짜를 얻는 방법?
- 10. CVS : 태그가 생성 된 날짜를 얻는 방법?
- 11. QCalendarWidget에 표시된 모든 날짜를 얻는 방법
- 12. VC++ : 파일의 시간과 날짜를 얻는 방법?
- 13. 아이튠즈 연결 계정에서 주문 날짜를 얻는 방법?
- 14. 날짜/시간 형식에서 날짜를 얻는 방법
- 15. 프로세스의 마지막 활성 날짜를 얻는 방법?
- 16. 마지막 날 금요일 날짜를 얻는 깔끔한 방법
- 17. 특정 시간대의 날짜를 얻는 방법? 모든
- 18. jQuery UI Datepicker로 선택한 날짜를 얻는 방법
- 19. jquery를 사용하여 현재 날짜를 얻는 방법?
- 20. 결과를 PHP의 미래 날짜로 제한하는 방법
- 21. WebDateChooser에서 미래의 날짜를 비활성화하는 방법
- 22. netbeans에서 날짜를 얻는 방법은 무엇입니까?
- 23. PHP에서 날짜를 확인하는 방법?
- 24. SchemaUpdate의 미래?
- 25. Singularity의 미래
- 26. Delphi에서 파일의 생성/마지막 수정 날짜를 얻는 방법?
- 27. PostgreSQL 데이터베이스의 마지막 액세스/수정 날짜를 얻는 방법?
- 28. 간단한 질문 : Java에서 GQL 쿼리에 사용되는 현재 날짜를 얻는 방법?
- 29. Python에서 주어진 날짜 범위에서 sat 및 sun 날짜를 얻는 방법
- 30. SQL Server 2008 : 데이터 시작 날짜와 종료 날짜를 얻는 방법?
(http://mattgemmell.com/2008/12/08/what-have-you-tried/) –