nstimeinterval

iOS how to call a method on the minute, every minute

大城市里の小女人 提交于 2020-02-05 05:38:37
问题 I mean 12:01:00, 12:02:00 ... In iOS7, I want to call a method when minute of time is changed. In other words, if now is 01:55:47, then I want to call a method at 01:56:00 -> 01:57:00 -> 01:58:00 ... All I found about call a method is just about TimeInterval, but not I want. I've tried this code: NSTimeInterval roundedInterval = round([[NSDate date] timeIntervalSinceReferenceDate] / 60.0) * 60.0; NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:roundedInterval]; NSTimer *timer =

Change the time interval of a Timer

故事扮演 提交于 2020-01-21 23:44:46
问题 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 :/ 回答1: Reschedule the timer recursively like this

Measuring time Interval Since Now

ぃ、小莉子 提交于 2020-01-14 14:32:11
问题 anyone know or can provide some example code relating to "timeIntervalSinceNow" method... I need something like... time2(when app eneters foreground) - time1(when app enters background) = time3(the difference in times)... this is so i can use this number(pref in seconds) to calculate the time i have lost while the app has been in background !! I am having trying trying to create the date objects, receive the object and display/use in a label.... 回答1: timeIntervalSinceNow tells you the offset

NSTime create a timeInterval

倖福魔咒の 提交于 2020-01-14 06:43:42
问题 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

Swift Progress View with NSTimer

孤街浪徒 提交于 2020-01-13 06:43:09
问题 I have a Progress view bar that I would like to use to indicate time. This is my first project in Swift, and I am unsure how to go about this. So any help/ advise would be appreciated ... (Using Xcode 7.2 and Swift 2.0) Below Is my view controller. When 'btnPlaySession' is triggered, the content on the view controller is changed every 20 seconds. While the timer is counting to 20, id like to indicate this with the progress bar (so the progress bar resets, each time the content changes). class

Calculate time interval to 0.00 of the next day according to GMT in swift or objective-c?

為{幸葍}努か 提交于 2020-01-07 09:44:27
问题 I tried something like this: var calendar = Calendar.current var dayFutureComponents = DateComponents() dayFutureComponents.day = 1 // aka 1 day var d = calendar.date(byAdding: dayFutureComponents, to: Date()) ...//setting of d.hour, d.minute, d.second to zero and finding the difference between 2 dates The problem is for example my current GMT is +3 . So the result differs from one I need to achieve by 3 hours. How to fix this issue? 回答1: First create a Calendar for the UTC timezone. Second

Calculate time interval to 0.00 of the next day according to GMT in swift or objective-c?

淺唱寂寞╮ 提交于 2020-01-07 09:43:48
问题 I tried something like this: var calendar = Calendar.current var dayFutureComponents = DateComponents() dayFutureComponents.day = 1 // aka 1 day var d = calendar.date(byAdding: dayFutureComponents, to: Date()) ...//setting of d.hour, d.minute, d.second to zero and finding the difference between 2 dates The problem is for example my current GMT is +3 . So the result differs from one I need to achieve by 3 hours. How to fix this issue? 回答1: First create a Calendar for the UTC timezone. Second

Calculating StartDate and endDate of a day based on todays date. Swift 2

拜拜、爱过 提交于 2020-01-07 02:35:30
问题 I have the following function which i am using to calculate a start and end of todays date. It was working perfectly last week, i think it may have something to do with the clocks going forwards? func rangeOfPeriod(period: NSCalendarUnit, date: NSDate) -> (NSDate, NSDate) { let calendar = NSCalendar.currentCalendar() var startDate: NSDate? = nil var duration: NSTimeInterval = 0 calendar.rangeOfUnit(period, startDate: &startDate, interval: &duration, forDate: date) let endDate = startDate!

how to compare time with current date and time?

人走茶凉 提交于 2020-01-06 08:58:07
问题 In My application I have to complete a particular task in given time.So first i calculated the time complete the task in seconds and then add that time to the current that like this. NSDate *mydate = [NSDate date]; NSTimeInterval TotalDuraionInSec = sec.cal_time * 60; TaskCmpltTime = [mydate addTimeInterval:TotalDuraionInSec]; NSLog(@"task will be completed at%@",TaskCmpltTime); now I compare time like this if([CurrentTime isEqualToDate:AfterCmpltTime]){ NSLog (@"Time Finish"); } but I want

How to change the NSTimeInterval of an NSTimer after X seconds?

核能气质少年 提交于 2019-12-31 05:10:19
问题 I'm making an app in swift 2 where there is two timers. After 10 seconds I would like another timer to go faster. I have tried doing it like this but it didn't work (I'm trying to change the var time to 1): @IBOutlet var displayTimeLabel: UILabel! var startTimer = NSTimeInterval() var timer = NSTimer() var timer2:NSTimer = NSTimer() var time = 2.0 @IBAction func Start(sender: UIButton) { if !timer2.valid { timer2 = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: