我一直在绞尽脑汁寻找快速解决方案。
我需要根据特定时区的当前时间在特定时间触发 NSTime。
例如,我获取 PST 的当前时间:
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"HH:mm:ss";
NSCalendar * cal = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
[cal setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"PST"]];
NSDateComponents * comps = [cal components:NSHourCalendarUnit fromDate:now];
我看到时间是 2 (14) 获取 [comps hour],我需要在当天下午 2:30 (14:30) 启动计时器。我需要帮助将其转换回来并进行数学计算以确定计时器触发之前还有多长时间。我将根据当前时间设置几个不同的计时器。当我查看 PST 时间时,我知道计时器和时间设置是在 GMT 中完成的。这是另一个转折...
提前致谢...
最佳答案
我自己解决了这个问题..但是谢谢你的提示...
if ([date earlierDate:newDate] == date) // it is before 7AM... fire at 7AM
等等......
关于ios - NSDate 数学?现在和 future 的Fire计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7459171/