C++ date & time with milliseconds
11,053
If you are using c++11, you should use chrono which allow you to manage time easier. It gives you a few methods to "cast" your time in whatever units you want (seconds to milliseconds, ...) and can manage ctime variables too.
Author by
bytecode77
„What I cannot create, I do not understand.“ - Richard Feynman bytecode77.com
Updated on June 22, 2022Comments
-
bytecode77 almost 2 years
Requirement
I need to retrieve the date and time including milliseconds in C++11 on Windows. If possible, beginning earlier than 1970.
I also need to be able to extract year, month, day, hour, second and millisecond from the date/time variable.
What I've tried
time()
only returns seconds.clock()
doesn't return a date, only time since last system start. Good for measuring elapsed time, tho.
Note: It only has to work with Windows. Linux is not required.