Created
June 9, 2021 19:01
-
-
Save gsdayton98/406ac7669f09fc8a97ed2630d1033c61 to your computer and use it in GitHub Desktop.
OSX Timespec print
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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