liebus

NSDate를 NSString으로 또는 반대 경우 본문

예전꺼(2014년이전꺼)/iOS

NSDate를 NSString으로 또는 반대 경우

리베스 2011. 2. 26. 17:29


1. NSDate를 NSString으로 

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
   [formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; 

    NSString *strDate = [formatter stringFromDate:[NSDate date]]; 
    NSLog(@"%@", strDate); 




2. NSString을 NSDate 으로 

     NSString *strDate = @"2011-12-04"
     NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
     [strDate setDateFormat:@"yyyy-MM-dd"]; 

     NSDate *date = [[NSDate alloc] init]; 
     date = [date dateFromString:date]; 
     NSLog(@"%@", [date description]); 

'예전꺼(2014년이전꺼) > iOS' 카테고리의 다른 글

UIView 터치이벤트  (0) 2011.03.28
알림 창 - UIAlertView 만들기  (0) 2011.03.28
상위 view 의 Controller를 사용하고자 할때  (0) 2011.02.22
뷰 간의 이동  (3) 2011.02.21
ModalViewController  (0) 2011.02.18
Comments