Tag: nstimeinterval

calculating 'timeIntervalSinceNow' with a negative value (CLLocation example)?

i don’t understand this example from the doc : the timeIntervalSinceNow method should show a positive value, but how can we reach “5” as mentioned in the code? (i think it’s either 0 more or less, or -10 , -20, -30 etc… but how can we get a positive value such as 5?) : – […]

NSTime create a timeInterval

I have the following code in my application in the method updateLabel2: timeLeft = [[NSDate date] timeIntervalSinceDate:[[NSUserDefaults standardUserDefaults] objectForKey:@”lastDate”]]; [[self timer] setText:[NSString stringWithFormat:@”Time Remaining: %f”, timeLeft]]; //Set the label text Note that timer is a label. and earlier, the following code is executed: [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@”lastDate”]; self.repeatTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateLabel2) userInfo:nil […]

Number of weeks in month

I have the following code: NSDate *dateNow = [[NSDate alloc] init]; NSTimeInterval timeDifference = [usersDate timeIntervalSinceDate:dateNow]; // Get the system calendar NSCalendar *sysCalendar = [NSCalendar currentCalendar]; // Create the NSDates NSDate *date1 = [[NSDate alloc] init]; NSDate *date2 = [[NSDate alloc] initWithTimeInterval:timeDifference sinceDate:date1]; // Get conversion to months, days, hours, minutes unsigned int unitFlags = […]

dateWithTimeIntervalSince1970 not returning correct date

I have the following method below that is meant to retrieve and convert a unixTimeStamp from an API call to a NSDate object that I can easily manipulate and use. For some reason, this returns wrong values. An example would be when the unixTimeStamp is 1385152832, the date SHOULD be Fri, 22 Nov 2013 20:40:31 […]

how to pause and resume NSTimer in iphone

hello I am developing small gameApp. I need to pause the timer,when user goes to another view [say settings view]. when user comes back to that view , I need to resume the timer. can anybody solve this issue … Thanks in Advance…

How to parse an ISO-8601 duration in Objective C?

I’m looking for an easy way to parse a string that contains an ISO-8601 duration in Objective C. The result should be something usable like a NSTimeInterval. An example of an ISO-8601 duration: P1DT13H24M17S, which means 1 day, 13 hours, 24 minutes and 17 seconds.

Compare current time with two times-of-day strings

How can i get time like “11:30” formate so that i want to compare it with the following: strOpenTime = @”10:00″; strCloseTime = @”2:00″; so how can i get current time like as above open/close time format and i want if the current time is inside the interval open/close time? Thanks in advance..!!

How to Get time difference in iPhone

I have 2 arrays with time values in it. They are in the following format. mm:ss:hundreds of a sec. I want to get the difference between the two [lastObjects] in the arrays. NSDate is not working because the last value is in hundredsth of a sec. A question. If the second date is larger than […]

NSTimeInterval to NSDate

How can I convert a NSTimeInterval to NSDate? Think of it like a stopwatch. I want the initial date to be 00:00:00, and I have a NSTimeInterval of X seconds. I need to do it like this because the NSTimeInterval needs to be converted to an int by using lround to round up, then converted […]

Change the time interval of a Timer

here is my question: Is it possible to increase the scheduledTimerWithTimeInterval:2 for example of “3” after 10 seconds in ViewDidLoad for example. E.g., from this: [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(createNewImage) userInfo:nil repeats:YES]; to this: [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(createNewImage) userInfo:nil repeats:YES]; thank you sorry for my english I french :/