2012-02-16 155 views
0

我将日期转换为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

它给你什么? – mit3z 2012-02-16 07:50:01

+0

d的输入请在这里写下。 – 2012-02-16 08:03:52

+0

检查我的答案它的工作 – Hiren 2012-02-16 08:17:21

回答

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

+0

不使用大写“YYYY”,因为你得到错误的结果使用小“yyyy”字母 – Hiren 2012-02-17 06:50:26