ios - NSDate returns a negative NSTimeInterval -
i have following code:
- (void)pointsstarteddisplaying { static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ dispatch_async(dispatch_get_main_queue(), ^{ self.timestarteddisplayingpoint = [nsdate date]; self.stopbutton.enabled = yes; [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(updateelapsedtime:) userinfo:nil repeats:yes]; }); }); } - (void)updateelapsedtime:(nstimer *)timer { nstimeinterval elapsedtimedisplayingpoints = [self.timestarteddisplayingpoint timeintervalsincedate:[nsdate date]]; self.elapsedtimevaluelabel.text = [nsstring stringwithformat:@"%f seconds", elapsedtimedisplayingpoints]; }
however, value of elapsedtimedisplayingpoints
accurate, except negative each time. why return -3, -4, -5,
etc?
if receiver earlier anotherdate, return value negative. case example. can use fabs() positive value.
Comments
Post a Comment