2015-05-14 60 views
0

我有一點點問題。 請看看這裏並理解這個問題。NSDateFormatter在設置日期時沒有給出正確的響應

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setLocale:[NSLocale systemLocale]]; 
    [dateFormatter setDateFormat:@"dd-MMM-yyyy"]; 
    self.datePicker.userInteractionEnabled=YES; 
    NSString *dateString=[dateFormatter stringFromDate:datePicker.date]; 

這是我的區塊,我正在返回一個日期。但是當我在那裏設置NSLocale那麼這不會給我適當的迴應。

我想DATEdd-MMM-yyyy(24-MAR-2008)甲。但它給響應:

iOS8.0和後者 - >24 M03-2004

iOS7.0和舊版 - >24 Month03-2004

由於一些依賴我不能刪除[dateFormatter setLocale:[NSLocale systemLocale]];從我上面的塊。 請建議我如何處理這個問題,

+1

[DATEFORMAT setTimeZone:[NSTimeZone localTimeZone];而不是 [dateFormatter setLocale:[NSLocale systemLocale]];你會很好去 –

+0

你能分享你的datepicker.date值嗎? – Mukesh

+0

@adnan你的答案是正確的。 –

回答

3

嘗試使用

[dateFormatter setLocale:[NSLocale currentLocale]]; 

insteade的

[dateFormatter setLocale:[NSLocale systemLocale]]; 

這將返回你想要的格式。

3

這將解決您的問題

[dateFormatter setLocale:[NSLocale currentLocale]]; 

[dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; 
相關問題