time_t The Wikipedia article in the article sheds light on this. The bottom line is that the type time_t not guaranteed in the C specification. Here is an example of what you can try:
Try stringstream .
#include <string> #include <sstream> time_t seconds; time(&seconds); std::stringstream ss; ss << seconds; std::string ts = ss.str();
A good wrapper around the above method is Boost lexical_cast:
#include <boost/lexical_cast.hpp> #include <string> time_t t; time(&t); std::string ts = boost::lexical_cast<std::string>(seconds);
Wikipedia at time_t:
The time_t data type is the data type in the ISO C library defined for storing system time values. Such values ββare returned from the standard time() library function. This typedef is a type defined in the standard header. ISO C defines time_t as an arithmetic type, but does not specify any particular type , range, resolution, or encoding. Also unspecified values ββare arithmetic operations applied to time values.
Unix and POSIX-compatible systems implement the time_t type as a signed integer (usually 32 or 64 bits) that represents the number of seconds since the Unix era : midnight UTC from January 1, 1970 (not counting the second of the jump). Some systems handle negative time values ββcorrectly, while others do not. Systems using the 32-bit time_t type are susceptible to the 2038 problem .
user195488
source share