Search code examples
iphoneobjective-cnsdatensdateformatter

How to print the time with AM/PM format in iPhone?


I want to print the time from date picker but with the AM/PM. I can print the time, but it never prints the AM/PM. How can I do this?


Solution

  • You could use this document for more information NSDateFormatter Class Reference .An example could be:

    NSDate* date = [NSDate date];
    NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"MM/dd/yyyy"];
    
    [formatter setTimeStyle:NSDateFormatterFullStyle];
    NSLog(@"date=%@",[dateFormatter stringFromDate:date]);