2012-02-16 154 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