2011-02-09 28 views
0

我嘗試添加時間信息到一個URL地址。添加時間到URL地址

例如:

http://www.test.de/output/iphone.txt?%Y%m%d%H%M%S

這樣。

這是我第一次嘗試:

首先,我想收到當前時間:

NSDate *currentDate = [NSDate date]; // aktuelles Datum und die Uhrzeit 
    NSString *strDate = [[currentDate 
          dateWithCalendarFormat:@"%Y%m%d%H%M%S" timeZone:nil] description]; 

+ 
    NSString *siteString = @"http://www.test.de/output/iphone.txt"; 
NSURL *siteURL = [NSURL URLWithString:siteString];    
    NSString *myString = [NSString stringWithContentsOfURL:siteURL encoding:NSASCIIStringEncoding error:&error]; 

現在我有兩個變量,strDatesiteString。 我想這些字符串結合起來,最後我想有以下字符串:

NSString *link = [siteString "+" ? "+" strDate] 

該字符串應該是這樣的:

http://www.test.de/output/iphone.txt?YYYYmmddHHMMss

回答

0

使用標準的字符串格式化函數來串聯兩件一起...

[NSString stringWithFormat:@"%@?%@",siteString,strDate] 
+0

謝謝:)它的工作。 – Dwain 2011-02-09 11:52:35