【发布时间】:2011-07-12 14:55:22
【问题描述】:
我正在尝试将字符串转换为日期。已使用以下代码。但是弄错了日期。
谢谢,
NSString *dateString = [NSString stringWithFormat:@"12-07-2011"];
//NSString *dateString = [NSString stringWithFormat:@"%d-%d-%d", selectedDate.day, selectedDate.month, selectedDate.year];
NSLog(@"%@",dateString);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateFormat:@"dd-mm-yyyy"];
NSDate* d = [dateFormatter dateFromString:dateString];
NSLog(@"%@",d);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Selected Date" message: [NSString stringWithFormat:@"%@",d] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
【问题讨论】:
-
你需要进一步解释。你得到什么日期?
标签: iphone objective-c nsdate