Skip to content

Instantly share code, notes, and snippets.

@kantoniak
Created April 13, 2017 12:04
Show Gist options
  • Save kantoniak/d58103623d0d7a7748fbc2040810428f to your computer and use it in GitHub Desktop.
Save kantoniak/d58103623d0d7a7748fbc2040810428f to your computer and use it in GitHub Desktop.
std::chrono example - getting unix timestamp
#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;
}
@kantoniak
Copy link
Author

@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