日期转换

时间:2015-04-27 05:46:56

标签: ios objective-c iphone

我有一个字符串30-07-2013我要转换为30 June。 我正在使用

 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateFormat:@"dd/MM/YYYY"];
 NSDate *date = [dateFormat dateFromString:@"30-07-1983"];

他们显示回复1984-12-24 18:06:32 +0000

2 个答案:

答案 0 :(得分:1)

试试这个

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MM-yyyy"];
NSDate *date = [dateFormat dateFromString:@"30-07-2013"];

 [dateFormat setDateFormat:@"dd MMM"];
NSString *strDate=[dateFormat stringFromDate:date];
NSLog(@"strDate : %@",strDate);

答案 1 :(得分:0)

请试试这个

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MM-yyyy"];
NSDate *date = [dateFormat dateFromString:@"30-07-1983"];

NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitDay | NSCalendarUnitMonth) fromDate:date];

NSLog(@"%d %@",(int)[components day],[[[NSDateFormatter new] monthSymbols] objectAtIndex:(components.month-1)]);