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?
Use below lines of code
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"hh:mm a"];
NSString *str_date = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"str_date:%@",str_date);
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]);
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