Created
May 19, 2015 14:51
-
-
Save 1ace/a66b75eeafc200c14280 to your computer and use it in GitHub Desktop.
Unix timestamp with microsecond precision
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> // std::chrono::high_resolution_clock, std::chrono::duration | |
#include <iostream> // std::cout | |
#include <iomanip> // std::fixed | |
int main() { | |
auto now = std::chrono::high_resolution_clock::now(); | |
auto timestamp = std::chrono::duration<double>(now.time_since_epoch()).count(); | |
std::cout << std::fixed << timestamp << std::endl; | |
} |
As an explanation, I made this to be able to track time in shell scripts with more precision than date +%s
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code uses the
chrono
library, which is part of C++11. You may need to add the compile flag-std=c++11
(or equivalent).