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!
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!
Check my answer to this question, you will get all the info you need here:
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;
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...