NSString与NSDate互转
1。NSDate 转换成
字符串
NSDate convert to NSString:
NSDate convert to NSString:
1.
NSDateFormatter
*dateFormatter = [[NSDateFormatter alloc] init];
2.
[dateFormatter
setDateFormat:@
"yyyy-MM-dd HH:mm:ss"
];
3.
NSString
*strDate = [dateFormatter stringFromDate:[NSDate date]];
4.
NSLog(@
"%@"
,
strDate);
5.
[dateFormatter
release];
2。 字符串转换成NSSdate:
NSString convert to NSDate:1.
NSDateFormatter
*dateFormatter = [[NSDateFormatter alloc] init];
2.
[dateFormatter
setDateFormat:@
"yyyy-MM-dd HH:mm:ss"
];
3.
NSDate
*date = [dateFormatter dateFromString:@
"2010-08-04 16:01:03"
];
4.
NSLog(@
"%@"
,
date);
5.
[dateFormatter
release];