2011-10-03 69 views
4

我有這樣的代碼效果很好,但我不知道這是否是調用stringWithFormat正確的方式,因爲在文檔%d是int和我傳遞一個長:這是調用stringWithFormat時長時間使用的正確說明符嗎?

long seconds = (long)[[NSDate date]timeIntervalSince1970]; 
    NSString *unixTimestamp = [NSString stringWithFormat:@"date=%d", seconds]; 

謝謝提前!

+0

http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html –

回答

5

嘗試%ld

NSString *unixTimestamp = [NSString stringWithFormat:@"date=%ld", seconds]; 

摘要從printf文檔(的NSString的stringWithFormat格式遵循相同的標準如printf函數):

升(ELL)
用於指定後續的d ,i,o,u,x或X轉換 說明符適用於長符號或無符號長參數

相關問題