<pre name="code" class="cpp">
#include <time.h>
#include <sys/time.h>
#include <string>
#include <sstream>
using namespace std;
string getTimeInString()
{
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm *ptm = gmtime(&tv.tv_sec);
string strTime;
strTime.reserve(32);
size_t size = strftime(&strTime[0], 32, "%F %T.", ptm);
strTime.resize(size);
stringstream ss;
ss << tv.tv_usec;
strTime += ss.str();
return strTime;
}