0

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...

rsirota
  • 321
  • 3
  • 15
  • Are you looking to always fire your timer at 14:30, or are you always wanting to fire in 30 minutes from now? – Alan Moore Sep 18 '11 at 02:53
  • Fire it at 14:30 if the current PST time is before 14:30 – rsirota Sep 18 '11 at 03:46
  • The problem stems when I go over to the next day GMT since I'm on PST – rsirota Sep 18 '11 at 03:47
  • So you already tried setting the components to 14:30 and setting your NSTimer and that didn't work? Can you put that code up as well? – Alan Moore Sep 18 '11 at 03:55
  • If you want to fire the timer 27 minutes in the future, that's 27 minutes in all time zones. Simply calculate the time delta and set a timer to fire at the appropriate time interval from "now". – Hot Licks Sep 18 '11 at 04:12
  • Here is a better example. It's 12:04PM PST and I need to fire a NSTimer at 14:30 PST and if its 15:20 I need to fire a time at 19:00. All PST. – rsirota Sep 18 '11 at 20:31

1 Answers1

1

I solved the problem myself.. But thanks for the tips...

if ([date earlierDate:newDate] == date) // it is before 7AM... fire at 7AM

and so on....

rsirota
  • 321
  • 3
  • 15