public member function
<chrono>

std::chrono::time_point::time_since_epoch

duration time_since_epoch() const;
Time since epoch
Returns a duration object with the time span value between the epoch and the time point.

The value returned is the current value of the internal duration object.

参数



返回值

The time span between the epoch and the time_point.
durationis a member type, defined as an alias of its second class template parameter (Duration), which is an instantiation of duration.

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// time_point::time_since_epoch
#include <iostream>
#include <chrono>

int main ()
{
  using namespace std::chrono;

  system_clock::time_point tp = system_clock::now();
  system_clock::duration dtn = tp.time_since_epoch();

  std::cout << "current time since epoch, expressed in:" << std::endl;
  std::cout << "periods: " << dtn.count() << std::endl;
  std::cout << "seconds: " << dtn.count() * system_clock::period::num / system_clock::period::den;
  std::cout << std::endl;

  return 0;
}

可能的输出
current time since epoch, expressed in:
periods: 1338280396212871
seconds: 1338280396


另见