且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++是否等同于Linux中Python的time.time()?

更新时间:2023-02-12 21:46:30

要获取以纪元为单位的当前时间(以秒为单位)作为浮点值,可以将duration_cast设置为浮点持续时间类型:

To get the current time since the epoch in seconds as a floating-point value, you can duration_cast to a floating-point duration type:

#include <chrono>

double fractional_seconds_since_epoch
    = std::chrono::duration_cast<std::chrono::duration<double>>(
        std::chrono::system_clock::now().time_since_epoch()).count();