1
使用NSDateFormatter,這是我輸入:NSDateFormatter和setDateFormat:和SSS
00:20:11,026 (NSString)
,這裏是輸出,我想:
"00:20:11,026"; (NSDate)
,但我得到的是:
"1970-01-01 00:20:11 +0100" (NSDate)
// SSS is missing and there is too much information...
這裏是我編碼:
...
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm:ss,SSS"];
[dateFormatter dateFromString:@"00:20:11,026"];
...
你說得對!爲什麼我沒有想到這個!現在,有沒有一種方法可以正確的方式進行nslogging?我必須強制重寫描述方法嗎? – jlink 2011-05-27 16:26:26
那麼,通常如果你想獲得NSDate的特定字符串表示,你可以使用NSDateFormatter的'-stringFromDate:'方法。所以,而不是'NSLog(@「%@」,日期);',你會'NSLog(@「%@」,[dateFormatter stringFromDate:date]);'覆蓋-description可以工作,但它是overkill =) – 2011-05-27 16:32:11
非常感謝你! – jlink 2011-05-27 17:21:22