nstimeinterval

What constant represents “never” for an NSTimeInterval?

守給你的承諾、 提交于 2019-12-13 02:26:30
问题 NSTimeInterval is a double , thus it cannot take a nil , and 0 represents something that should happen immediately. Is there a constant that means "never"... or an astronomically huge value, or should I use -1? 回答1: As suggested by s.bandara, use a very large number to treat a time interval as "infinite" or "never". DBL_MAX is the largest value a double can hold. This macro is declared in float.h : #define DBL_MAX (9.999999999999999e999) 来源: https://stackoverflow.com/questions/28200472/what

Using mod operator in iOS app

谁说胖子不能爱 提交于 2019-12-12 08:33:41
问题 I have an NSTimeInterval that is stored as a double. I would like to get the amount of minutes that are inide of the second value using the % operator. minutes = secondValue % 60; where minutes is declared as double minutes The result is that XCode says "Invalid operands to binary %" Thoughts? 回答1: The OP changed their question, so here is my new answer: You want to do minutes = floor(secondsValue) / 60; You want int division, not modulus. 回答2: From the C standard, section 6.5.5

How to add the output of multiple timers

百般思念 提交于 2019-12-11 12:35:43
问题 My utility app will have 20 individual timers, laid out like this: - (void)updateTimer { NSDate *currentDate = [NSDate date]; NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate]; NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"mm:ss"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]]; NSString *timeString=[dateFormatter

NSTimeInterval format for POST with JSON objective-c to DateTime .net format

≯℡__Kan透↙ 提交于 2019-12-11 07:54:55
问题 I retrieve the NSTimeInterval as follows: NSTimeInterval milisecondedDate = ([[NSDate date] timeIntervalSince1970] * 1000); Which logs this: UNIX Timestamp: "1307710190993.865967" I only want the value before the dot to send with JSON like this: "/Date(1307710131826+0200)/" Any suggestions? Thanks in advance, 回答1: Get the current timestamp in milliseconds since 1970 UNIX Timestamp. NSTimeInterval millisecondedDate = ([[NSDate date] timeIntervalSince1970] * 1000); Format the milliesecondedDate

How to add 5 seconds to a timer

旧街凉风 提交于 2019-12-11 03:57:01
问题 I'm trying to make a timer showing the following - hours : minutes : seconds : milliseconds. Here is my code: var timer = NSTimer() var startTime = NSTimeInterval() func updateTime() { var currentTime = NSDate.timeIntervalSinceReferenceDate() var elapsedTime : NSTimeInterval = currentTime - startTime let hours = UInt8(elapsedTime / 3600.0) elapsedTime -= (NSTimeInterval(hours) * 3600) let minutes = UInt8(elapsedTime / 60.0) elapsedTime -= (NSTimeInterval(minutes) * 60) let seconds = UInt8

Reconciling CACurrentMediaTime() and deviceCurrentTime

人盡茶涼 提交于 2019-12-11 03:23:57
问题 I am trying to synchronize several CABasicAnimations with AVAudioPlayer . The issue I have is that CABasicAnimation uses CACurrentMediaTime() as a reference point when scheduling animations while AVAudioPlayer uses deviceCurrentTime . Also for the animations, CFTimeInterval is used, while for sound it's NSTimeInterval (not sure if they're "toll free bridged" like other CF and NS types). I'm finding that the reference points are different as well. Is there a way to ensure that the sounds and

Difference between timestamp stored and current date

ぐ巨炮叔叔 提交于 2019-12-07 20:53:54
问题 I have linked up an app that I have made to an Firebase database. The app sends Firebase the time as a timeIntervalSinceReferenceDate when a button is pressed. An example of the value is - 498898978852.928 . I want this number to distinguish wether the user has pressed that same button more less than 48 hours ago. Is there a way to measure the time period of 48 hours or should I use a different method? I am using swift 2 and Xcode 7! 回答1: Swift 3. If you are using Swift 2, use NSDate //the

How to get NSTimeInterval value from last boot

白昼怎懂夜的黑 提交于 2019-12-07 11:38:48
问题 I need to get NSTimeInterval value from last device boot. I found CACurrentMediaTime() which suits this task, but in my app I am not using Core Animation and I don't think that this is the best way to include this framework just to get this function. Is there another way to get time in seconds from last boot more elegant way? 回答1: The NSTimeInterval value since the last system restart can be acquired more directly via the following Foundation object and method: [[NSProcessInfo processInfo]

Actually using UIDatePickerModeCountDownTimer as a timer

天大地大妈咪最大 提交于 2019-12-06 14:12:39
I am just trying to make a timer. I would like to use UIDatePickerModeCountDownTimer mode of the UIDatePicker , so that when the user simply selects say 15 mins in the picker, they are passed back to a screen that shows the value of 15 mins in a label that they can then count down from. As I have tried to get the value from the DatePicker, I realized that the picker passes back an NSTimeInterval that gets the current time in seconds: UIDatePicker *pickerView = [[UIDatePicker alloc] init]; NSTimeInterval new = (NSTimeInterval)pickerView.countDownDuration; So all I want is to know the value that