我使用日期格式化程序来获取新字符串,但在某些情况下 startDate 可以为 nil。
resultDate = [NSString stringWithFormat:@"%@", [formatter stringFromDate:startDate]];
然后 resultDate 获取 (null)
字符串 (NSTaggedPointerString),但如果格式化程序获取 nil 作为日期参数,我希望只获取 nil。
最佳答案
目前接受的答案实际上并不正确。
stringFromDate
确实在您将 nil
日期传递给它时返回 nil
。
你的字符串是 "(null)"的原因是因为 [NSString stringWithFormat:"%@", nil]
返回字符串 "(null)"
关于ios - 当 NSDate 为 nil 时,NSDateFormatter 返回(空)字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33829127/