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.
- Use duration property for getting the total duration of video
- 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
Looping Through Nsattributedstring Attributes to Increase Font Size
Swift - Get Local Date and Time
Add "Edit in Excel" or "Edit Photo" Extension
Uicollectionview Spacing Margins
iPhone Ad Hoc Build Using Xcode 4
Error When Trying to Obtain a Certificate: the Specified Item Could Not Be Found in the Keychain
iOS 11 - Keyboard Height Is Returning 0 in Keyboard Notification
Launch Image Not Showing Up in iOS Application (Using Images.Xcassets)
Calculating Bearing Between Two Cllocation Points in Swift
Linker Error in iOS (Duplicate Symbols for Architecture X86_64)
Open Uitableview Edit Action Buttons Programmatically
Why Is -Diddeselectrowatindexpath Not Being Called
Swiftui Datepicker Binding Optional Date, Valid Nil
Pull to Refresh Uitableview Without Uitableviewcontroller
How to Prevent the iPhone Screen from Dimming or Turning Off While My Application Is Running
Refresh Devices in Team Provisioning Profile Managed by Xcode 7
Uiapplication.Registerforremotenotifications() Must Be Called from Main Thread Only