-1

I have date which came from api and stored as string like

2013-05-09 09:30:00

and i want to show as

09-05-2013 09:30

in UILabel. I want to know how to use NSDateFormatter. Thanks in advance!

JDev
  • 15
  • 10

3 Answers3

0

Check my answer to this question, you will get all the info you need here:

Date formatter for the google calender API

Community
  • 1
  • 1
Antonio MG
  • 20,382
  • 3
  • 43
  • 62
0

Try

        NSString *str = @"2013-05-09 09:30:00";
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *dt = [dateFormatter dateFromString:str];

        NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
        [dateFormatter1 setDateFormat:@"dd-MM-yyyy HH:mm"];
        NSString *str1 = [dateFormatter1 stringFromDate:dt];
        NSLog(@"Formated date - %@", str1);//output -> 09-05-2013 09:30

        lbl.text = str1;
Girish
  • 4,692
  • 4
  • 35
  • 55
0

Once go through this,

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy''HH:mm"];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:162000];
NSString *formattedDateString = [dateFormatter stringFromDate:date];
NSLog(@"%@",[formattedDateString stringByReplacingOccurrencesOfString:@"'" withString:@" "]);

Here NSLog Prints like 03-01-2001 02:30 , for more here is apple document.

Hope it will helps you...

iSpark
  • 952
  • 7
  • 18