public static member function
<chrono>
std::chrono::system_clock::from_time_tstatic time_point from_time_t (time_t t) noexcept;
Convert from time_t
Converts t into its equivalent of member type time_point.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;
}
4533 days have passed since 1/1/2000
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4