0

I have time portion as a string and I want to parse it into date, as I have concern about the time portion of date. But when I parse it with the given format, result is nil. How should I parse my Time String?

Time String: 23:59

Method:

+(NSDate*)getDateFromStringProfile:(NSString*)strDate
{
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    [dateFormat setDateFormat:@"HH:mm"];
    [dateFormat setTimeZone:timeZone];


    NSDate *result =[dateFormat dateFromString:strDate];
    return result;
}

Result: nil

Muhammad Nabeel Arif
  • 19,140
  • 8
  • 51
  • 70

1 Answers1

0

Adding the locale worked for me. I added the following locale.

[dateFormat setLocale: [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];

And I got a NSDate object instead of nil. Thanks for comment @ZaneHelton

Muhammad Nabeel Arif
  • 19,140
  • 8
  • 51
  • 70