请问如何获取当前时间,精确到毫秒?

General1982 2008-07-14 03:00:22
请问如何获取当前时间,精确到毫秒?需要时间的型式为:200807131457123(其为2008年07月13日14时58秒123毫秒)。请给于指点谢谢!!
...全文
392 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jingang_xp 2011-05-16
  • 打赏
  • 举报
回复
mark
npuhuxl 2008-07-14
  • 打赏
  • 举报
回复
GetTickCount、QueryPerformanceCounter、QueryPerformanceFrequency可以使用吧
General1982 2008-07-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 elovenana 的回复:]
#include <stdio.h>
#include <time.h>
#include <sys/timeb.h>

int main()
{
struct timeb tp;
struct tm * tm;


ftime ( &tp );
tm = localtime ( & ( tp.time ) );

printf ( "%02d:%02d:%02d:%03d\n", ( tm -> tm_hour ) , ( tm -> tm_min ) ,
( tm -> tm_sec ), ( tp.millitm ) );


}
[/Quote]
把上面的输出改了一下。
我使用一下输出
cout<<tm ->tm_year<<tm ->tm_mon<<tm ->tm_yday<<tm ->tm_hour<<tm ->tm_min<<tm ->tm_sec<<tp.millitm<<endl;
输出的年月日为什么不正确?小时,分,秒结果是正确的。我还要用到年月日。


zhongguozhangzhong 2008-07-14
  • 打赏
  • 举报
回复
要是还没有明白
那就去http://bbs.palmjob.net/看看吧
冷月清晖 2008-07-14
  • 打赏
  • 举报
回复
SYSTEMTIME t;
GetLocalTime(&t);
sprintf(tmpbuf,"%04d-%02d-%02d\\%02d-%02d-%02d-%03d",
t.wYear,t.wMonth,t.wDay,t.wHour,t.wMinute,t.wSecond,t.wMilliseconds);
长安宁 2008-07-14
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <time.h>
#include <sys/timeb.h>

int main()
{
struct timeb tp;
struct tm * tm;


ftime ( &tp );
tm = localtime ( & ( tp.time ) );

printf ( "%02d:%02d:%02d:%03d\n", ( tm -> tm_hour ) , ( tm -> tm_min ) ,
( tm -> tm_sec ), ( tp.millitm ) );


}

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧