I have a problem with this method:
-(NSString *)getLastTimeMessageWithPeriod:(NSDate*)lastMessageDate
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
NSString *resultString = [dateFormatter stringFromDate: lastMessageDate];
return resultString;
}
In iPhone 4 (iOS 7.1 ) the resultString return " 12:32 "
In iPhone 5 (iOS 8 ) the resultString return " 12:32 Am "
What can be the problem that it makes it miss the period in iPhone 4 ?
I've just tested your provided code on my iOS 7.1 device, and it gave me "3:22", so problem is not device or OS version.
Problem is the locale, do like this and it will work
- (NSString *)getLastTimeMessageWithPeriod:(NSDate *)lastMessageDate
{
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"h:mm a"];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
return [dateFormatter stringFromDate:lastMessageDate];;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With