public static member function
<chrono>

std::chrono::system_clock::from_time_t

static time_point from_time_t (time_t t) noexcept;
Convert from time_t
Converts t into its equivalent of member type time_point.

Parameters

t
A value of time time_t.
time_t is a type defined in header <ctime>.

Return value

A time_point object representing the equivalent of t.
time_t is a type defined in header <ctime>.
time_point is a member type, defined as an alias of time_point<system_clock>.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// system_clock::from_time_t
#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>

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

  // create tm with 1/1/2000:
  std::tm timeinfo = std::tm();
  timeinfo.tm_year = 100;   // year: 2000
  timeinfo.tm_mon = 0;      // month: january
  timeinfo.tm_mday = 1;     // day: 1st
  std::time_t tt = std::mktime (&timeinfo);

  system_clock::time_point tp = system_clock::from_time_t (tt);
  system_clock::duration d = system_clock::now() - tp;

  // convert to number of days:
  typedef duration<int,std::ratio<60*60*24>> days_type;
  days_type ndays = duration_cast<days_type> (d);

  // display result:
  std::cout << ndays.count() << " days have passed since 1/1/2000";
  std::cout << std::endl;

  return 0;
}

Possible output:
4533 days have passed since 1/1/2000


See also