Time measurement interval since now

Does anyone know or can provide some sample code related to the timeIntervalSinceNow method ...

I need something like ... time2 (when app eneters foreground) - time1 (when the application enters the background) = time3 (time difference) ... this is so, I can use this number (pref in seconds) to calculate The time I lost when the app was in the background!

I am trying to create date objects, get the object and display / use in the label ....

+3
source share
3 answers

timeIntervalSinceNowindicates the offset NSDatefrom the current time. Do you want timeIntervalSinceDate::

NSDate *appEnteredForeground = ...;
NSDate *appEnteredBackground = ...;

NSTimeInterval difference = [appEnteredBackground timeIntervalSinceDate: appEnteredForeground];
+4
source

timeIntervalSinceDate::

//When app enters background:
self.backgroundDate = [NSDate date]; //this should be a property 
//...
//When the app comes back to the foreground:
NSTimeInterval timeSpentInBackground = [[NSDate date] timeIntervalSinceDate:self.backgroundDate];

NSTimeInterval - typedef double, . [NSDate date] NSDate .

+4

, , myles, timeIntervalSinceNow. inputDate NSDate ( [NSDate *inputDate = [NSDate date]; .

NSTimeInterval timeToAlert =[inputDate timeIntervalSinceNow];

- NSTimeInterval .

NSMutableString *timeinterval = [NSMutableString string];
[timeinterval appendFormat:@"%f",timeToAlert];

, , , . !

+4

All Articles