我想將字符串轉換爲日期時間對象,然後減去2個日期之間的差異。不過,我不斷收到一個無效的指針警告。日期格式爲20131209 02:34。我的代碼如下將字符串轉換爲日期並找出時差
NSDateFormatter *df =[[NSDateFormatter alloc]init];
[df setDateFormat:@"YYYYMMDD HH:MM"];
NSDate *currTime = [df dateFromString:self.currentTime];
NSDate *predicTime =[df dateFromString:self.predictedTime];
NSTimeInterval newtime=[predicTime timeIntervalSinceDate:currTime];
YYdd HH:MM是這個有效的日期格式? –
'[df setDateFormat:@「yyyyMMdd hh:mm」];' – Maulik
'self.predictedTime'和'self.currentTime'指向'NSString'實例的有效指針嗎? – FluffulousChimp