일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- install
- VISTA
- Objective-C
- mac
- 설치
- screen
- WebService
- 오브젝티브C
- 형식
- 링크
- windows
- Number
- 애플
- c#
- cagr48com
- 아이맥
- 볼링
- 아이폰
- 맥
- ObjectiveC
- 7932
- iPhone
- 윈도우즈7
- 퇴사
- 윈도구
- WSDL
- windows7
- Mobile
- 윈도구7
- java
- Today
- Total
A colossal Dreamer: GR鐵塔-天生我材
[아이폰:오브젝티브C] 날짜와 캘린더 그리고, 날짜조각 본문
아이폰OS에서 날짜와 연관된 클래스는 3개이고,
각각의 역할이 정해져 있다.
시스템수준의 날짜: NSDate
달력: NSCalendar
날짜조각: NSDateComponents
지역시간: NSTimeZone
NSDate 는 시스템간에 통용될 수 있는 오늘과 같은 하나의 시점을 표현하는 클래스이고,
NSDateComponents 는 인간이 알아먹을 수 있는 날짜이다.
NSTimeZone 은 NSCalendar에서만 사용이 가능한 것으로 UTC 기준의 시간을 지역시간으로 적용할 수 있다.
위의 두 날짜의 인간이 알아먹을 수 있는 표현로는 다르지만,
실제로는 하나의 날짜를 의미한다.
Getting a date’s components
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents =
[gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:today];
NSInteger day = [weekdayComponents day];
NSInteger weekday = [weekdayComponents weekday];
Creating a Date from Components
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setWeekday:2]; // Monday
[components setWeekdayOrdinal:1]; // The first day in the month
[components setMonth:5]; // May
[components setYear:2008];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:components];
참조: 애플개발자사이트
'Development > 아이폰' 카테고리의 다른 글
[아이폰:오브젝티브C] 앞뒤 공백문자 제거(Trim white space) (0) | 2010.02.19 |
---|---|
[아이폰:오브젝티브C] 1,000 과 같이 3자리마다 콤마(,) 추가 (0) | 2010.02.17 |
[아이폰:Xcode] Preprocessor Definitions (0) | 2010.02.04 |
[아이팟] 벽돌로부터의 탈출..~~ (0) | 2010.02.02 |
[아이폰:오브젝티브C] 형식 비교하기 (0) | 2010.01.28 |