2013-05-03 41 views
-1

格式化的NSDate我有來自API和string存儲像坐落在文本的UILabel

2013-05-09 09:30:00 

日期,我想表現出UILabel作爲

09-05-2013 09:30 

。我想知道如何使用NSDateFormatter。 在此先感謝!

回答

0

嘗試

 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; 
0

一旦通過這個,

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:@" "]); 

這裏NSLog打印像03-01-2001 02:30,更多here是蘋果文檔。

希望它能幫助你...

+0

OP要顯示日期作爲標籤文本。但你沒有回答這個問題。 – 2014-05-06 14:58:20