سؤال

I have string @"2/10/2014 10:12:12 AM" (month/day/year hour:minute:second am/pm) in this format. How to convert it into NSDate format. I feel it easy but not getting in same format.

هل كانت مفيدة؟

المحلول

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"MM/dd/yyyy hh:mm:ss a";

NSString *dateString = @"12/24/2014 10:32:42 PM";
NSDate *date = [formatter dateFromString:dateString];

NSLog(@"date: %@", [formatter stringFromDate:date]);

Next thing you'll need to figure out is the time zones.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top