Skip to content

Instantly share code, notes, and snippets.

@gsdayton98
Created June 9, 2021 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsdayton98/406ac7669f09fc8a97ed2630d1033c61 to your computer and use it in GitHub Desktop.
Save gsdayton98/406ac7669f09fc8a97ed2630d1033c61 to your computer and use it in GitHub Desktop.
OSX Timespec print
#include <ctime>
#include <sys/time.h>
#include <iostream>
std::ostream& operator<<(std::ostream& gozouta, const struct timespec& timspec) {
struct tm loctime;
char cbuf[512];
(void) ::localtime_r(&timspec.tv_sec, &loctime);
size_t nconv = ::strftime(cbuf, sizeof(cbuf), "%Y-%m-%d %H:%M:%S", &loctime);
gozouta << cbuf << "." << std::setfill('0') << std::setw(9) << timspec.tv_nsec;
return gozouta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment