Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format date by using NSDateFormatter

Tags:

iphone

I added a date picker to view. But when I select any date from the picker, it's shown this format:

Wednesday, December 14, 2011 1:50:52 PM India Standard Time

I want to change this format to

Wed, Dec 14 2011 1:50 PM

How can I get this format with NSDateFormatter?

like image 987
Nari Avatar asked Dec 13 '22 07:12

Nari


1 Answers

Try with below code .it will help you

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EEE, MMM dd yyyy hh:mm a"];//Wed, Dec 14 2011 1:50 PM
    NSString *str_date = [dateFormat stringFromDate:[NSDate date]];
    NSLog(@"str_date = %@",str_date);
like image 131
Narayana Avatar answered Jan 03 '23 04:01

Narayana