1

I am converting the string into date with the help of below code :

NSDateFormatter *fDateFormat = [[NSDateFormatter alloc] init];  
[fDateFormat setDateFormat:@"dd/MM/yyyy hh:mm a"];  
[fDateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];  
NSDate *dateFormat = [fDateFormat dateFromString:strDate];  

And passing string like "02/09/2013 05:10 AM" and I will get date perfect. But when we use time format 24 hours, then date is nil.

Can you please me out of this problem ?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Nirmalsinh Rathod
  • 5,079
  • 4
  • 26
  • 56
  • 1
    See [this answer](http://stackoverflow.com/a/6735644/581994). Playing with the phone's 12/24 setting mucks up NSDateFormatter unless you take special precautions. – Hot Licks Sep 02 '13 at 16:35

1 Answers1

2
NSDateFormatter *fDateFormat = [[NSDateFormatter alloc] init];  
[fDateFormat setDateFormat:@"dd/MM/yyyy hh:mm a"];  
[fDateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];  
NSDate *dateFormat = [fDateFormat dateFromString:strDate];  

[fDateFormat setDateFormat:@"dd/MM/yyyy HH:mm"];  
NSString *your24Format = [fDateFormat stringFromDate:dateFormat];

You can try above code, should be working fine :)

Wayne

Wayne Lai
  • 97
  • 6