Skip to content

Instantly share code, notes, and snippets.

@nickjacob
Created February 28, 2017 19:51
Show Gist options
  • Save nickjacob/fac51b5daa485829d1cf4ccd17592df3 to your computer and use it in GitHub Desktop.
Save nickjacob/fac51b5daa485829d1cf4ccd17592df3 to your computer and use it in GitHub Desktop.
Convert dispatch_time_t to NSNumber (ms)
/**
* Convert a dispatch_time_t to milliseconds.
* note that this only works if dispatch time is in the future,
* and is approximate (since the time now will be slightly different than
* the time you made the dispatch_time_t).
*/
static NSNumber * dispatch_future_to_ms(dispatch_time_t time) {
uint64_t abs = mach_absolute_time();
return @((time - abs) / NSEC_PER_MSEC);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment