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;
}
@Spixmaster

This comment has been minimized.

Copy link

@Spixmaster Spixmaster commented Mar 3, 2020

Thank you!

@kantoniak

This comment has been minimized.

Copy link
Owner Author

@kantoniak kantoniak commented Mar 3, 2020

@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