std::chrono::time_point::time_since_epoch
来自cppreference.com
< cpp | chrono | time point
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
std::chrono::duration time_since_epoch() const; |
||
返回一个表示之间的时间量std::chrono::duration*this的划时代的
clock
.原文:
Returns a std::chrono::duration representing the amount of time between *this and the
clock
's epoch.[编辑] 参数
(无)
[编辑] 返回值
本
time_point
clock
的划时代的之间的时间量原文:
the amount of time between this
time_point
and the clock
's epoch[编辑] 示例
#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'; }
Possible output:
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