Created
December 29, 2016 08:07
-
-
Save dtoma/cc3d5b2dd4c03a25886adededcc1e3b9 to your computer and use it in GitHub Desktop.
C++ timestamp with nanoseconds and timezone
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 <chrono> | |
#include <iomanip> | |
#include <iostream> | |
int main() { | |
auto now = std::chrono::high_resolution_clock::now(); | |
auto time = std::chrono::system_clock::to_time_t(now); | |
auto tm = *std::gmtime(&time); | |
// auto tm = *std::localtime(&time); | |
auto epoch = now.time_since_epoch(); | |
auto us = std::chrono::duration_cast<std::chrono::microseconds>(epoch).count() % 1000000; | |
std::cout << std::put_time(&tm, "%F %T.") << us << std::put_time(&tm, " %Z\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: