title: Convert Date from String in iOS?
body: <p>I am getting from my server a date as string like this <strong>"10/4/2013 10:00:00 PM"</strong>. Now I want only hours to display in my label.But the problem is am using the below code but not getting actual time.</p>
  
  <pre><code>-(NSString*)convert:(NSString*)strdate
  {
  
      NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
      [formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
      [formatter setLocale:[NSLocale systemLocale]];
     [formatter setDateFormat:@"dd/MM/yyyy HH:mm:ss a"];
      NSDate * date = [formatter dateFromString:strdate];
  
  
      NSDateFormatter* df = [[NSDateFormatter alloc]init];
      [df setDateFormat:@"hh:mm"];
      NSString *depResult = [df stringFromDate:date];
  
      NSLog(@"hours  %@ ", [df stringFromDate:date]);
  
      return depResult;
  }
  </code></pre>
  
  <p>and am giving String input as <strong>"10/4/2013 9:00:00 PM"</strong> and getting output as <strong>"05:30"</strong>.Please correct me where am doing wrong.Thanks</p>