Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 NSDate 对象,我需要检查它是否已经通过。如果是这样,把那个日期变成明天的日期,但我不能在这个过程中丢失像 TimeZone 这样的信息。
你能帮我吗?
NSDate *date = ...; if ([[NSDate date] timeIntervalSinceDate:date] > 0) { date = [date dateByAddingTimeInterval:24*60*60]; }
NSDate没有时区信息。它只是自其纪元以来经过的秒数的薄层。您可以使用日历和时区将其转换为NSDateComponents,在那里摆弄日期,然后将其格式化为新的NSDate.
NSDate
NSDateComponents