您的位置:首页 > 其它

学习备忘--获取当前日期时间(精确到毫秒)

2012-08-07 17:43 330 查看
#include
#include
#include
#include
using namespace std;
typedef char * PCHAR;
void Now(PCHAR buff);
int main()
{
char buff[128];
Now(buff);
cout << buff << endl;
return 0;
}
void Now(PCHAR buff)
{
struct timeb tp;
struct tm *tm;
ftime(&tp);
tm = localtime(&tp.time);
sprintf(buff, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d.%.3d",
1900+ tm->tm_year,
1 + tm->tm_mon,
tm->tm_yday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec,
tp.millitm);
}

欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  struct include