Skip to content

[cpp,c++,std::chrono] time 02: epoch time: chrono::time_point, time_since_epoch

std::chrono::time_point<Clock, Duration>::time_since_epoch

#include <chrono>
#include <iostream>

namespace chrono = std::chrono;

int main() {
    auto time_now = chrono::system_clock::now();
    auto time_since_epoch = time_now.time_since_epoch();
    std::cout << time_since_epoch.count() << std::endl;
If you do not want auto:
#include <chrono>
#include <iostream>

namespace chrono = std::chrono;

int main() {
    chrono::time_point time_now = chrono::system_clock::now();
    chrono::duration<chrono::system_clock::rep, chrono::system_clock::period> time = time_now.time_since_epoch();
    std::int64_t count = time.count();
    std::cout << "time_since_epoch: " << count << std::endl;
time_since_epoch: 16562365095077906


No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Form options

Submitted comments will be subject to moderation before being displayed.