NSDateFormatter will not parse string with timezone that includes colon

前端 未结 4 1057
心在旅途
心在旅途 2021-01-16 20:50

I\'m trying to transform @\"Fri, 26 Aug 2011 10:51:00 +02:00\" into an NSDate:

[dateFormatter setDateFormat:@\"EEE, dd MMM yyyy HH:         


        
4条回答
  •  无人共我
    2021-01-16 21:24

    You can use the getObjectValue:forString:range:error: method to parse dates that have the colon in the timezone:

    // test date formatting
    NSString *dateString = @"2012-04-11T18:34:19+00:00";
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZ";
    NSDate *date;
    NSError *error;
    [formatter getObjectValue:&date forString:dateString range:nil error:&error];
    

提交回复
热议问题