Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.