How can I get current time (I need hours, minutes, seconds) crossplatform in c++? I saw here make structure of values but there are a lots of another stuff that I don’t need. And memory is very important here.
How can I get current time (I need hours, minutes, seconds) crossplatform in c++?
Share
The routines in
<time.h>are cross-platform and in fact required to be available for conforming implementations of ISO C. Usetimeto retrieve the elapsed time since 1970, andlocaltimeorgmtimeto break that down into hours, minutes, and seconds, as needed.You shouldn’t be concerned that
struct tmuses too much memory to store unneeded fields unless you are programming extremely memory-constrained devices, in which case you probably aren’t looking for a cross-platform solution.