Getting Time Elapsed in Objective-C

Getting time elapsed in Objective-C


NSDate *start = [NSDate date];
// do stuff...
NSTimeInterval timeInterval = [start timeIntervalSinceNow];

timeInterval is the difference between start and now, in seconds, with sub-millisecond precision.

Display Time Elapsed Since Start of Game in Objective C

starting a timer with

self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(whatever you've called the method where you update the display to show current time) userInfo:nil repeats:YES];

will update your display ever second

Total time and time elapsed in JWPlayer - objective C

You can get the these information from JWPlayer API reference itself.

  1. Use duration property for getting the total duration of video
  2. Use playbackPosition property for getting the elapsed time

Usage:

double duration = [jwPlayer duration];
NSNumber *time = [jwPlayer playbackPosition];

How to log a method's execution time exactly in milliseconds?


NSDate *methodStart = [NSDate date];

/* ... Do whatever you need to do ... */

NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart];
NSLog(@"executionTime = %f", executionTime);

Swift:

let methodStart = NSDate()

/* ... Do whatever you need to do ... */

let methodFinish = NSDate()
let executionTime = methodFinish.timeIntervalSinceDate(methodStart)
print("Execution time: \(executionTime)")

Swift3:

let methodStart = Date()

/* ... Do whatever you need to do ... */

let methodFinish = Date()
let executionTime = methodFinish.timeIntervalSince(methodStart)
print("Execution time: \(executionTime)")

Easy to use and has sub-millisecond precision.

How to get current elapsed time of iPhone music player?

I believe you're looking for -[MPMusicPlayerController currentPlaybackTime];. This value returns the current position of the playhead, or rather the elapsed time in the currently playing track.

NSTimeInterval interval = [[MPMusicPlayerController iPodMusicPlayer] currentPlaybackTime];


Related Topics



Leave a reply



Submit