2012-12-12 5 views

답변

2
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"d"]; 
NSInteger day = [[dateFormat stringFromDate:[NSDate date]] intValue]; 
0

NSDate으로 시작하여 NSDateFormatter을 실행하십시오.

NSDate *theDate; 

// Set theDate to the date you want 
// For example, theDate = [NSDate date]; to get today's date 

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
formatter.dateFormat = @"d"; 
NSString *theDayString = [formatter stringFromDate:theDate]; 
int theDay = theDayString.intValue; 

NSLog (@"%d", theDay); 

theDay 당신이 찾고있는 값을 포함합니다 : 여기

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

3

위의 모든 대답은이를 수행하는 나쁜 방법입니다. 올바른 방법 :

NSDate *date = [NSDate date]; 
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
NSDateComponents *components = [calendar components:NSDayCalendarUnit fromDate:date]; 
NSInteger day = components.day; 
관련 문제