NSDate 数学?现在和未来的Fire计时器
我一直在绞尽脑汁寻找一个快速的解决方案。
我需要根据特定时区的当前时间在特定时间触发 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];
我看到获取 [comps hour] 的时间为 2 (14),并且我需要在当天下午 2:30 (14:30) 触发计时器。我需要帮助将其转换回来并进行数学计算以确定计时器触发之前还有多长时间。我将根据当前时间设置几个不同的计时器。当我查看 PST 时间时,我知道计时器和时间设置是在 GMT 中完成的。这是另一个转折...
提前致谢...
I have been racking my brains on this one looking for a quick solution.
I need to fire off a NSTime at a specific time based on the current time in a specific time zone.
For example, I get the current time in 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];
I see that the time is 2 (14) getting [comps hour] and I need to fire a timer at 2:30PM (14:30) on that day. I need help converting it back and doing the math to say how long it is before the timer fires. I will be setting up several different timers based on the current time. While I am looking at the time in PST I know that the timers and setting of the time is done in GMT. That's another twist...
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己解决了这个问题..但是谢谢你的提示...
等等....
I solved the problem myself.. But thanks for the tips...
and so on....