Objective-C之 NSDateComponent取得年月日代码

Sample Code:

#import <Foundation/Foundation.h>
#import "Enum.h"
int main(int argc,const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSDate * senddate = [NSDate date];
    NSCalendar * cal = [NSCalendar currentCalendar];
    
    NSUInteger unitFlags = NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit;
    NSDateComponents * component = [cal components:unitFlags fromDate:senddate];
    
    NSInteger year = [component year];
    NSInteger month = [component month];
    NSInteger day = [component day];
    
    NSLog(@"%4d/%2d/%2d",year,month,day);
    
   
    
    
    [pool drain];
    return 0;

}

你可能感兴趣的:(Objective-C,xcode,NSDateComponent,NSCalendar)