#include <chrono>
#include <ctime>
#include <iostream>
int main()
{
////
std::chrono::system_clock::time_point syc_now =
std::chrono::system_clock::now();
std::chrono::system_clock::time_point syc_default ;
std::chrono::system_clock::duration syc_duration = syc_now -
syc_default;
double syc_seconds = double(syc_duration.count()) *
std::chrono::system_clock::period::num /
std::chrono::system_clock::period::den;
std::cout << syc_seconds << std::endl;
////
std::chrono::steady_clock::time_point stc_now = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point stc_default ;
std::chrono::steady_clock::duration stc_duration = stc_now -
stc_default;
double std_seconds = double(stc_duration.count()) *
std::chrono::steady_clock::period::num /
std::chrono::steady_clock::period::den;
std::cout << std_seconds << std::endl;
////
std::chrono::high_resolution_clock::time_point hrc_now = std::chrono::high_resolution_clock::now();
std::chrono::high_resolution_clock::time_point hrc_default ;
std::chrono::high_resolution_clock::duration hrc_duration =
hrc_now - hrc_default;
double hrc_seconds = double(hrc_duration.count()) *
std::chrono::high_resolution_clock::period::num /
std::chrono::high_resolution_clock::period::den;
std::cout << hrc_seconds << std::endl;
////
std::time_t tt_now = std::time(nullptr);
std::cout << tt_now << std::endl;
return 0;
}
/* Output:
1.50396e+09
33785.6
33785.6
1503960804
*/
Reference: http://www.cplusplus.com/reference/chrono/
Tuesday, August 29, 2017
C++11: Time
Three time systems were added. Here is an example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment