Answer the question
In order to leave comments, you need to log in
How to convert unix time to std::string?
Main goal: convert UNIX time to std::string
When I tried to use code like this:
std::string unixtimeToString( time_t ts )
{
// _CRT_SECURE_NO_WARNINGS
enum { numCStringSize = 0x80 };
const char strTimestampFmt[] = "%a, %Y-%b-%d, %H:%M:%S";
char timeCStr[ numCStringSize ];
std::tm * tmInfo = gmtime( &ts );
std::strftime( &timeCStr[0], numCStringSize, strTimestampFmt, tmInfo );
return std::string( timeCStr );
}
std::string unixtimeToString( uint32_t timeStamp )
{
using namespace boost::posix_time;
using namespace boost::gregorian;
ptime unixEpoche( date( 1970, Jan, 1 ) );
ptime ts( unixEpoche + time_duration( 0, 0, timeStamp ) );
return to_simple_string( ts );
}
Answer the question
In order to leave comments, you need to log in
In my opinion, the most reasonable thing is to move the function code to a separate file, and wrap it with pragma push / pop with the annoying warning disabled.
As for the slowness of your program using boost conversion - this is a little strange, because if you access each file and then convert the time, then it is obvious that accessing the file system should be the bottleneck.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question