2015-11-06 92 views
-2

當我分析我的xml我會得到日期這樣Fri Nov 06 12:29:39 IST 2015的NSDate格式返回null?

這是我的Xcode部分

NSLog(@"%@",parsedElementContent); 
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
[formatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss Z"]; 
[_currentItem setPubDate:[formatter dateFromString:[self trimString:parsedElementContent]]]; 

如果這部分返回null

[formatter dateFromString:[self trimString:parsedElementContent]] 
- (NSString *)trimString:(NSString *)originalString{ 
    NSString * trimmedString; 
    trimmedString = [originalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
    return trimmedString; 
} 

我這這部分是錯誤的@ 「EEE,d MMM YYYY HH:MM:SS Z」

+1

您應該使用的格式,如:[格式化setDateFormat:@「MMM DD HH:MM:SS「IST 'yyyy「]; –

+1

您的日期格式不符合在你拿到了所有的字符串日期。 – Larme

+0

謝謝you..i didnt注意到 – Bangalore

回答

2

您的字符串表示是

Fri -> EEE (indicate shot day name) 
Nov -> MMM (indicate month) 
06 -> HH (indicate two digit date) 
01 -> mm (indicate two digit month) 
00 -> ss (indicate two digit minute) 
IST -> IST (indicate current time standerd) 
2015-> yyyy (indicate years) 

所以設置像

[formatter setDateFormat:@"EEE MMM dd HH:mm:ss 'IST' yyyy"]; 

並設置更多的NSDate格式,Click MeClick Me

+0

不要忘記添加一個地方,因爲該日期本地化。 – rckoenes

+0

對不起...週五2006年11月12點29分三十九秒IST 2015年,這是我的格式... – Bangalore

+0

其再次顯示空 – Bangalore