Getting the time: C++, NOT 'C'

I did a search and found nothing. I could only find the C way of doing it. Unfortunately, i program C++, so my question is how do i get my program to get the 'system' time and put it into a variable for use? Thank you for your time, i apprecciate it!
I could only find the C way of doing it. Unfortunately, i program C++


C++ is (very nearly) a strict superset of C. What works in C also works in C++.
There's boost::datetime, which is pretty cool, but that's about it.
Does anyone know if it's been included in C++11?
The "C" libraries are still part of C++, they just go under a different name. Look at #include <ctime>.
alright. Thank you. :)
C++11 has a suspicious new chrono header, which probably has more to do with multithreading than date/time.

http://en.cppreference.com/w/cpp/chrono

But if you do figure it out, return and let us know how you did it.
Nothing suspicious about <chrono>, I use it (although in production I prefer boost.date_time due to better I/O).

Current time is

auto now = std::chrono::system_clock::now();
Last edited on
Cubbi, how can one convert that now thing to an std::string or C array?
well, i managed to get a timer displaying the seconds, minutes or hours (minutes and hours require you to divide the seconds by 60, and 60 again for hours) from some day at midnight in 1970 or whatever... I cant figure out how to get it to show me the current time though. Doesnt matter, it's still helpful for timer operations. I would however like to timestamp my data and such...
Catfish, that's the reason I use boost.date_time for serious jobs, boost's time points and durations can be simply serialized with operator>>. To serialize chrono's time points and durations, you need the non-standard chrono_io library or equivalent.
Topic archived. No new replies allowed.