开发者

Correct form for dateFormatter

I'm pulling dates from an xml feed that has this form

12/10/2010 19:30:00

and I'm using this form of the setDateFormat method to recognize the date

[dateFormatter setDateFormat:@"MM/dd/yyyy  HH:mm:ss"];

but it's constantly throwing an exception saying the date that results is nil, leading me to suspect I don't have the right form to recognize the date.

Do I have the correct form, or am I missing something?

Thanks for any insight you can provide on this.

Here is more information about the function in which this error is thrown - and the error occurs on the first date that it finds - which is this date 12/10/2010 19:30:00:

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

    if ([elementName isEqualToString:@"item"]) {
        [item setObject:self.currentTitle forKey:@"title"];
        [item setObject:self.currentType forKey:@"type"];
        [item setObject:self.currentSummary forKey:@"description"];
    [item setObject:self.currentTeacher forKey:@"teacher"];
    [item setObject:self.currentDate forKey:@"pubdate"];
    [item setObject:self.currentLink forKey:@"link"];               

    // Parse date here
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];


    [dateFormatter setDateFormat:@"MM/开发者_开发技巧dd/yyyy HH:mm:ss"];


    NSDate *date = [dateFormatter dateFromString:self.currentDate];


        [item setObject:date forKey:@"date"];

        [items addObject:[item copy]];
    }
}


Format looks good to me. Check the date return from XML before formatting. if you are having any other tags/characters than date dateFormatter gives error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜