C#에 너무 익숙해서인지 자꾸 비슷한 걸 찾게 되는군요. C#의 Date형에는 멤버로 year, month, day 있어서 편하게 사용했었기에, 같은 방식으로 사용할수 있도록 만든 코드입니다.
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:locale];
[locale release];
// Get year
[dateFormatter setDateFormat:@"yyyy"];
int year = [[dateFormatter stringFromDate:today] intValue];
// Get Month
[dateFormatter setDateFormat:@"MM"];
int month = [[dateFormatter stringFromDate:today] intValue];
// Get Day
[dateFormatter setDateFormat:@"dd"];
int day = [[dateFormatter stringFromDate:today] intValue];
[dateFormatter release];
'컴퓨터 > cocos2d & objective C' 카테고리의 다른 글
[cocos2d, iOS 4.0] jpg 사용시 발생하는 문제해결 (0) | 2010.07.02 |
---|---|
[objective C] New Line 개행문자 (0) | 2010.04.08 |
[objective C] int -> string 변환시, 두자리 형식으로 표시하기 - String Format Specifiers, 문자열 형식 지정자관련 (0) | 2010.03.17 |
cocos2d 사운드 출력 코드 (0) | 2010.03.15 |
아이폰 프로그래밍 - cocos2d 설치 및 템플릿 추가하기 (3) | 2010.02.02 |