Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Wednesday, January 05, 2005

tstring ToString(boost::posix_time::ptime &time_data)


tstring ToString(boost::posix_time::ptime &time_data)
{
/*
time to yyyymmdd-hhmmss
//test code:
boost::posix_time::ptime timestamp = boost::posix_time::second_clock::local_time(); ;
std::cout<< ToString(timestamp) <<std::endl;
*/
std::basic_stringstream<TCHAR> ts;
ts<<boost::gregorian::to_iso_string(time_data.date()) <<_T("-")
<< std::setw(2)<<std::setfill(_T('0')) << time_data.time_of_day().hours();
ts<<std::setw(2)<<std::setfill(_T('0')) <<time_data.time_of_day().minutes();
ts<<std::setw(2)<<std::setfill(_T('0'))<<time_data.time_of_day().seconds();
return ts.str();
}

0 Comments:

Post a Comment

<< Home