为什么获取的时间不正确?

墨子翼 2010-05-12 04:43:53
SYSTEMTIME ti;
CString str;
GetSystemTime(&ti);
str.Format("%02d:%02d:%02d:%03d",(ti.wHour),ti.wMinute,ti.wSecond,ti.wMilliseconds);
MessageBox(str,"",0);
用这个获取时间,为什么16点获得的 ti.wHour 是8。
...全文
129 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
axlshn 2010-05-12
  • 打赏
  • 举报
回复
CTime::GetCurrentTime
dinjay 2010-05-12
  • 打赏
  • 举报
回复
想说的都被说了....J下F
sjdev 2010-05-12
  • 打赏
  • 举报
回复
FormatGmt
Eleven 2010-05-12
  • 打赏
  • 举报
回复
ls都说了,lz可以结贴了
wangli820 2010-05-12
  • 打赏
  • 举报
回复
用 GetLocalTime 才是当地时间, GetSystemTime 是跟时区有关的
rayyear 2010-05-12
  • 打赏
  • 举报
回复

SYSTEMTIME systime;
memset(&systime, 0, sizeof(SYSTEMTIME));
GetLocalTime(&systime);
CString str;
char * buf = new char[20];
if ( NULL == buf)
{
str = "";
}

memset(buf, 0, 20);
_stprintf(buf,
TEXT("%04d-%02d-%02d %02d:%02d:%02d"),
systime.wYear, systime.wMonth, systime.wDay,
systime.wHour, systime.wMinute, systime.wSecond);

str = buf;
delete [] buf;

wltg2001 2010-05-12
  • 打赏
  • 举报
回复
GetSystemTime获取的是系统时间,也叫格林威治时间或者全球标准时间,简称叫做UTC。本地时间就是相对于UTC而言的,比如中国北京是在东8区,相对于UTC就多了8个小时。一般使用到的时间都是使用本地时间,也就是调用函数GetLocalTime。
bilaopao 2010-05-12
  • 打赏
  • 举报
回复
GetLocalTime
liruda 2010-05-12
  • 打赏
  • 举报
回复
Retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC), 还需要转换吧.
许文君 2010-05-12
  • 打赏
  • 举报
回复
用getlocaltime
liruda 2010-05-12
  • 打赏
  • 举报
回复
获得的时间应该是GMT时间.

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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