Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 2.29 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. NSDateFormatter strange behavior
  2. NSDateFormatter *df = [[NSDateFormatter alloc] init];
  3. [df setDateFormat:@"yyyy-MM-dd"];
  4.        
  5. - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  6. {
  7.     // do something with the data
  8.     // receivedData is declared as a method instance elsewhere
  9.     NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
  10.  
  11.     NSString *json_string = [[NSString alloc] initWithData:receivedData
  12.                                                   encoding:NSUTF8StringEncoding];
  13.     NSDictionary* datos = [parser objectWithString:json_string error:nil];
  14.  
  15.     [connection release];
  16.     [receivedData release];
  17.     [parser release];
  18.     [json_string release];
  19.  
  20.     NSArray* data = [datos objectForKey:kRootKey];
  21.  
  22.     cierres = [[NSMutableArray alloc] initWithCapacity:data.count];
  23.  
  24.     NSDateFormatter *df = [[NSDateFormatter alloc] init];
  25.     [df setDateFormat:@"yyyy-MM-dd"];
  26.  
  27.     for (int i = 0; i < data.count; i++)
  28.     {
  29.         NSDictionary* object = [data objectAtIndex:i];
  30.  
  31.         NSLog(@"Parser: %@, Aper: %@, Cierre: %@", [object objectForKey:kFederacionKey], [object objectForKey:kAperturaKey], [object objectForKey:kCierreKey]);
  32.         NSString* fedName = [object objectForKey:kFederacionKey];
  33.         NSDate* aperDate = [df dateFromString: [object objectForKey:kAperturaKey]];
  34.         NSDate* cierreDate = [df dateFromString: [object objectForKey:kCierreKey]];
  35.  
  36.         CierreData* cierreData =
  37.             [[CierreData alloc] initWithFederationName:fedName
  38.                                               openDate:aperDate
  39.                                           andCloseDate:cierreDate];
  40.         [cierres addObject:cierreData];
  41.  
  42.         [cierreData release];
  43.     }
  44.  
  45.     [delegate dataReceived];
  46. }
  47.        
  48. NSDateFormatter *formater=[[NSDateFormatter alloc]init];
  49.         [formater setDateFormat:@"yyyy-MM-dd h:mm:ss a"];
  50.         [formater setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
  51.  
  52.         NSDate *now1 = [formater dateFromString:[NSString stringWithFormat:@"%@ 11:07:00 PM",[[arrdate objectAtIndex:i]valueForKey:@"date"]]];
  53.  
  54.         NSLog(@"%@",now1);
  55.        
  56. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  57. NSTimeZone *timezone = [NSTimeZone timeZoneWithName:@"Europe/Madrid"];
  58. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  59. [dateFormatter setTimeZone:timezone];