I'm looking for something that can hold the current time, but is independent of the user adjusting the OS's time, and that can be converted to a std::string and back and that meets the requirements of LessThanComparable and EqualityComparable, I search online but I couldn't find anything suitable.
I can't use The C++ Standard Chrono Library because: std::chrono::system_clock you can change the OS's time std::chrono::steady_clock and std::chrono::high_resolution_clock cannot be converted to a std::string and back
std::chrono::high_resolution_clock can only be used to get time deltas, generally for the purposes of benchmarking/profiling. It can't be used for timestamping because it's not a real time clock.
If you want to get the actual current time your only real option is Network Time Protocol. Note:
1. You will have to hardcode the servers you want to use.
2. NTP doesn't have any provisions to guarantee that the server you're talking to is actually the one you wanted, so there's no guarantee that the system is not configured to resolve names or route IP addresses to itself and run an NTP server that lies. If this is a problem, you will have to make your own time protocol that does provide authentication, and you will have to run your own server.
std::chrono::time_point<> is used to represent a point in time (internally holds a time interval from the start of the clock's epoch). std::chrono::time_point<> is a NumericType that is LessThanComparable and EqualityComparable. http://en.cppreference.com/w/cpp/chrono/time_point/operator_cmp
The clocks in std::chrono provide the static member function now() which returns the current time point.
The only clock in std::chrono that is guaranteed to be monotonic and the one most suitable for measuring time intervals is std::chrono::steady_clock. The time points of this clock always move forward in physical time and it is not affected by changes to system wall clock time.
(std::chrono::system_clock follows the system wall clock; if the user adjusts the OS's current time, it will follow the adjustment. And std::chrono::high_resolution_clock need not be steady.)
OK, I see that I can convert a time point to milliseconds to a std::string, but how do I convert a std::string that contains milliseconds to a time point?