nstimeinterval

Difference between timestamp stored and current date

*爱你&永不变心* 提交于 2019-12-06 12:37:48
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! Swift 3. If you are using Swift 2, use NSDate //the first button press, this is a double but assume it's a timeInterval let firstPress = 498898978.928 let date =

calculating 'timeIntervalSinceNow' with a negative value (CLLocation example)?

做~自己de王妃 提交于 2019-12-05 17:41:46
i don't understand this example from the doc : the timeIntervalSinceNow method should show a positive value, but how can we reach "5" as mentioned in the code? (i think it's either 0 more or less, or -10 , -20, -30 etc... but how can we get a positive value such as 5?) : - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { // test the age of the location measurement to determine if the measurement is cached // in most cases you will not want to rely on cached measurements NSTimeInterval locationAge = -

Calculate time difference in Cocoa

杀马特。学长 韩版系。学妹 提交于 2019-12-04 08:27:52
问题 I have got two timevalues in the format: %H%M%S (E.G.161500) These values are text-based integers. Is there a simple function in Cocoa that calculates the difference between these two integers using a 60 seconds and minutes scale? So if time 1 = 161500 time 2 = 171500 timedifference = 003000 回答1: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"HHmmss"]; NSDate *date1 = [dateFormatter dateFromString:@"161500"]; NSDate *date2 =

Convert NSTimeInterval to NSString in iPhone?

蓝咒 提交于 2019-12-03 07:33:29
问题 How to covert the NSTimeInterval to NSString? I have NSTimeInterval today = [[NSDate date] timeIntervalSince1970]; I have to give "today" as input as NSString. 回答1: NSTimeInterval is just a double type so you can convert it to string using +stringWithFormat: method NSTimeInterval today = [[NSDate date] timeIntervalSince1970]; NSString *intervalString = [NSString stringWithFormat:@"%f", today]; 回答2: -(NSString*)formattedDuration:(NSTimeInterval)interval{ NSDateComponentsFormatter *formatter =

Calculate time difference in Cocoa

北城余情 提交于 2019-12-02 23:21:31
I have got two timevalues in the format: %H%M%S (E.G.161500) These values are text-based integers. Is there a simple function in Cocoa that calculates the difference between these two integers using a 60 seconds and minutes scale? So if time 1 = 161500 time 2 = 171500 timedifference = 003000 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"HHmmss"]; NSDate *date1 = [dateFormatter dateFromString:@"161500"]; NSDate *date2 = [dateFormatter dateFromString:@"171500"]; NSTimeInterval diff = [date2 timeIntervalSinceDate:date1]; // diff =

Convert NSTimeInterval to NSString in iPhone?

荒凉一梦 提交于 2019-12-02 20:18:05
How to covert the NSTimeInterval to NSString? I have NSTimeInterval today = [[NSDate date] timeIntervalSince1970]; I have to give "today" as input as NSString. NSTimeInterval is just a double type so you can convert it to string using +stringWithFormat: method NSTimeInterval today = [[NSDate date] timeIntervalSince1970]; NSString *intervalString = [NSString stringWithFormat:@"%f", today]; 来源: https://stackoverflow.com/questions/4278129/convert-nstimeinterval-to-nsstring-in-iphone

How do I find the time interval remaining from NSTimer

时间秒杀一切 提交于 2019-12-02 16:23:03
问题 I have set a NSTimer.scheduledTimerWithTimeInterval method which has an interval every 20 minutes. I want to be able to find out how much time is left when the the app goes into background mode. How do I find out how much time is left from the interval? Thanks 回答1: You have access to a NSTimer's fireDate , which tells you when the timer is going to fire again. The difference between now and the fireDate is an interval you can calculate using NSDate's timeIntervalSinceDate API. E.G. something

How do I find the time interval remaining from NSTimer

不问归期 提交于 2019-12-02 10:41:06
I have set a NSTimer.scheduledTimerWithTimeInterval method which has an interval every 20 minutes. I want to be able to find out how much time is left when the the app goes into background mode. How do I find out how much time is left from the interval? Thanks You have access to a NSTimer's fireDate , which tells you when the timer is going to fire again. The difference between now and the fireDate is an interval you can calculate using NSDate's timeIntervalSinceDate API . E.G. something like: let fireDate = yourTimer.fireDate let nowDate = NSDate() let remainingTimeInterval = nowDate

Number of weeks in month

拈花ヽ惹草 提交于 2019-12-01 15:11:07
I have the following code: NSDate *dateNow = [[NSDate alloc] init]; NSTimeInterval timeDifference = [usersDate timeIntervalSinceDate:dateNow]; // Get the system calendar NSCalendar *sysCalendar = [NSCalendar currentCalendar]; // Create the NSDates NSDate *date1 = [[NSDate alloc] init]; NSDate *date2 = [[NSDate alloc] initWithTimeInterval:timeDifference sinceDate:date1]; // Get conversion to months, days, hours, minutes unsigned int unitFlags = NSWeekCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSSecondCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit |

Number of weeks in month

拜拜、爱过 提交于 2019-12-01 12:14:39
问题 I have the following code: NSDate *dateNow = [[NSDate alloc] init]; NSTimeInterval timeDifference = [usersDate timeIntervalSinceDate:dateNow]; // Get the system calendar NSCalendar *sysCalendar = [NSCalendar currentCalendar]; // Create the NSDates NSDate *date1 = [[NSDate alloc] init]; NSDate *date2 = [[NSDate alloc] initWithTimeInterval:timeDifference sinceDate:date1]; // Get conversion to months, days, hours, minutes unsigned int unitFlags = NSWeekCalendarUnit | NSYearCalendarUnit |