获取当前时间并转为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; }
相关文章推荐
- Git使用方法
- NDK使用CURL
- jdk1.8安装后查看Java -version出错。
- onAttachedToWindow()在整个Activity生命周期的位置及使用
- [Swift]枚举
- 【Objective-C】空指针和野指针
- 欢迎使用CSDN-markdown编辑器
- 80x86保护模式(1)
- Android Drawable 那些不为人知的高效用法
- Leetcode Unique Paths II
- BZOJ 1006 [HNOI2008]神奇的国度 弦图的最小染色
- java动态代理(JDK和cglib)
- decorView和window之间的层级及关系
- ls --color的使用
- 结构型模式之四——外观模式
- php解决key没有双引号的问题
- 观察变量值修改的位置
- 硬币问题(贪心)
- GRUB- "No suitable mode found"
- handsontable-chosen-editor