Difference between std::system_clock and std::steady_clock?

From N3376: 20.11.7.1 [time.clock.system]/1: Objects of class system_clock represent wall clock time from the system-wide realtime clock. 20.11.7.2 [time.clock.steady]/1: Objects of class steady_clock represent clocks for which values of time_point never decrease as physical time advances and for which values of time_point advance at a steady rate relative to real time. That is, the clock … Read more

C++ Add months to chrono::system_clock::time_point

Overview This is a very interesting question with several answers. The “correct” answer is something you must decide for your specific application. With months, you can choose to do either chronological computations or calendrical computations. A chronological computation deals with regular units of time points and time durations, such as hours, minutes and seconds. A … Read more

std::put_time implementation status in GCC?

See TODO extended iomanip manipulators std::get_time and std::put_time for gcc 4.8.0. See also Cross Platform way to get the time of day? claiming that is not implemented in 4.7.0. UPDATE: As the gcc developer Jonathan Wakely confirmed below: The std::get_time and std::put_time manipulators are still missing in gcc 4.9. UPDATE: Jonathan Wakely closed this ticket … Read more

How to convert std::chrono::time_point to calendar datetime string with fractional seconds?

If system_clock, this class have time_t conversion. #include <iostream> #include <chrono> #include <ctime> using namespace std::chrono; int main() { system_clock::time_point p = system_clock::now(); std::time_t t = system_clock::to_time_t(p); std::cout << std::ctime(&t) << std::endl; // for example : Tue Sep 27 14:21:13 2011 } example result: Thu Oct 11 19:10:24 2012 EDIT: But, time_t does not contain … Read more

Extract year/month/day etc. from std::chrono::time_point in C++

You can only extract this information from a system_clock::time_point. This is the only system-supplied clock that has a relationship with the civil calendar. Here is how to get the current time_point using this clock: system_clock::time_point now = system_clock::now(); You can then convert this to a time_t with: time_t tt = system_clock::to_time_t(now); Using the C library … Read more

What are the uses of std::chrono::high_resolution_clock?

There are none. Sorry, my bad. If you are tempted to use high_resolution_clock, choose steady_clock instead. On libc++ and VS high_resolution_clock is a type alias of steady_clock anyway. On gcc high_resolution_clock is a type alias of system_clock and I’ve seen more than one use of high_resolution_clock::to_time_t on this platform (which is wrong). Do use <chrono>. … Read more

Resolution of std::chrono::high_resolution_clock doesn’t correspond to measurements

I’m going to guess you are using Visual Studio 2012. If not, disregard this answer. Visual Studio 2012 typedef‘s high_resolution_clock to system_clock. Sadly, this means it has crappy precision (around 1 ms). I wrote a better high-resolution clock which uses QueryPerformanceCounter for use in Visual Studio 2012… HighResClock.h: struct HighResClock { typedef long long rep; typedef std::nano period; typedef std::chrono::duration<rep, … Read more