日期格式无法正常工作

时间:2012-02-16 07:28:51

标签: iphone objective-c ios ipad ios4

我将日期记入stringdate format是这样的,string

datenotification=20-02-2012

现在我想将其更改为

20-feb-2012

但出于检查目的,我只是将其放入dateformatter并打印出来,但它显示的日期不正确

NSDateFormatter* currentdateformate = [[NSDateFormatter alloc] init];
[currentdateformate setDateFormat:@"dd-MM-YYYY"];
NSDate *d=[currentdateformate dateFromString:dateNotification];
NSString *str3=[currentdateformate stringFromDate:d];
[currentdateformate release];

1 个答案:

答案 0 :(得分:2)

嘿检查这个例子

 NSString *string = @"12-02-2000";
 NSDateFormatter* currentdateformate = [[NSDateFormatter alloc] init];
 [currentdateformate setDateFormat:@"dd-MM-yyyy"];
 NSDate *d=[currentdateformate dateFromString:string];
 [currentdateformate setDateFormat:@"dd-MMM-yyyy"];
 NSString *str3=[currentdateformate stringFromDate:d];
 [currentdateformate release];
 NSLog(@"S %@",str3);

输出S 12-feb-2012