user1396086
user1396086

Reputation:

How to get time from ios datepicker in 12 hour format with AM , PM?

I m using date picker in my project and I m getting selected date as 24 hour format after applying format attribute as hh:mm . I can get 12 hour format date from by converting it using conditions but I want to know some direct method to get 12 hour format time from date picker with AM , PM . If anybody knows shortest way to do it then please indicate me by your answer. Thank you!

Upvotes: 0

Views: 6425

Answers (1)

Prince Kumar Sharma
Prince Kumar Sharma

Reputation: 12641

I have made a method for this , try it

-(NSString*)getTimetoFill
{
 NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
 [outputFormatter setDateFormat:@"h:mm a"];

 NSString *timetofill = [outputFormatter stringFromDate:datepicker.date];
 return timetofill;
}

Upvotes: 5

Related Questions