Instead of using std::chrono::system_clock::now();
I would like to set my own specific hours\minutes\seconds.
Similar to how one would go about using struct tm
to manually construct a date-time.
What is the best way of doing this?
Any clock provided by <chrono>
refers to an epoch, which is different from the point in time one your input delta refers to (based on the comments below the question). So you shouldn't try to use std::chrono::time_point
instances (the instantiations clocks deal with), but instead a std:chrono::duration
. The latter is agnostic of any reference point in time, as is your input. Depending on the unit of this input, pick one of the predefined std::duration
instantiations, e.g.
#include <chrono>
const int timestamp = getSecondsSinceMidnight();
const std::chrono::seconds sec{timestamp};
Now you can proceed with that, e.g. subtract another timestamp etc.