Created
April 13, 2017 12:04
-
-
Save kantoniak/d58103623d0d7a7748fbc2040810428f to your computer and use it in GitHub Desktop.
std::chrono example - getting unix timestamp
This file contains 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 <ctime> | |
#include <iostream> | |
int main() { | |
// std::chrono only | |
auto now = std::chrono::system_clock::now(); | |
std::cout << "std::chrono only: " << std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count() << std::endl; | |
std::cout << "with std::ctime: " << std::chrono::seconds(std::time(NULL)).count() << std::endl; | |
} |
@Spixmaster, this snippet comes from an article: http://antoniak.in/blog/2017/04/14/managing-time-std-chrono/. You may find it interesting.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!