在线文档教程
C++
应用 | Utilities

std::chrono::time_point::time_since_epoch

STD::时间::时间[医]要点::时间[医]自[医]时代

duration time_since_epoch() const;(since C++11) (until C++14)
constexpr duration time_since_epoch() const;(since C++14)

返回duration表示之间的时间量*thisclock%27S时代

参数

%280%29

返回值

这段时间time_pointclock%27S时代

二次

#include <iostream> #include <chrono> #include <ctime> int main() { std::chrono::time_point<std::chrono::system_clock> p1, p2, p3; p2 = std::chrono::system_clock::now( p3 = p2 - std::chrono::hours(24 std::time_t epoch_time = std::chrono::system_clock::to_time_t(p1 std::cout << "epoch: " << std::ctime(&epoch_time std::time_t today_time = std::chrono::system_clock::to_time_t(p2 std::cout << "today: " << std::ctime(&today_time std::cout << "hours since epoch: " << std::chrono::duration_cast<std::chrono::hours>( p2.time_since_epoch()).count() << '\n'; std::cout << "yesterday, hours since epoch: " << std::chrono::duration_cast<std::chrono::hours>( p3.time_since_epoch()).count() << '\n'; }

二次

可能的产出:

二次

epoch: Wed Dec 31 19:00:00 1969 today: Tue Jun 19 12:05:37 2012 hours since epoch: 372256 yesterday, hours since epoch: 372232

二次

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/crono/time[医]点/时间[医]自[医]时代