NSDate,NSString转化

NSDate to NSString
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", strDate);
[dateFormatter release];
NSString to NSDate
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:@"2010-08-04 16:01:03"];
NSLog(@"%@", date);
[dateFormatter release];
//String to number
NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; 
[f setNumberStyle:NSNumberFormatterDecimalStyle]; 
NSNumber * myNumber = [f numberFromString:@"42"]; 
[f release]; 

你可能感兴趣的:(NSString)