NSDate returns nil for the correct set of NSDateFormatter

I get the date in NSString format as below.

Entrance: datestring = 04/30/2013 04:49 PM

I am using the NSDateformatter format as follows to convert this NSString to NSDate.

Format: dateFormat = dd / MM / yyyy hh: mm a

I still get date conversion to Nil. Please help as I do not understand this problem. Here is my code snippet to explain what I do in a utility function.

  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setDateFormat:dateFormat];
  NSDate *date = [dateFormatter dateFromString:dateString];
  return date;
0
source share
1 answer

Try it....

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm a"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
NSDate *date = [dateFormatter dateFromString:@"30/04/2013 04:49 PM"];
NSLog(@"%@",date);
0
source

Source: https://habr.com/ru/post/1527493/


All Articles