Skip to content

Instantly share code, notes, and snippets.

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;

This comment has been minimized.

Copy link

@Spixmaster Spixmaster commented Mar 3, 2020

Thank you!


This comment has been minimized.

Copy link
Owner Author

@kantoniak kantoniak commented Mar 3, 2020

@Spixmaster, this snippet comes from an article: You may find it interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment