您的位置:首页 > 其它

获取当前时间并转为string

2015-10-20 13:56 393 查看
<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;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: