如何使用 C++ 将 Windows 系统时钟设置为正确的本地时间?
现在我做了这样的事情:
SYSTEMTIME st;
st.wHour = 6;
st.wMinute = 23;
BOOL result = SetSystemTime(&st);
目标是让它在我的本地计算机上显示准确的时间。当我运行该程序时,它会将其更改为 8:23 而不是 6:23。我怎样才能让它显示正确的当地时间?
Right now I do something like this:
SYSTEMTIME st;
st.wHour = 6;
st.wMinute = 23;
BOOL result = SetSystemTime(&st);
The goal is to get it to show that exact time on my local machine. When I run the program it changes it to 8:23 instead of 6:23. How can I get it to show the correct local time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SetSystemTime()
期望提供的时间采用 UTC 格式。如果要使用当地时间设置时间,请使用SetLocalTime()
。SetSystemTime()
expects the provided time to be in UTC. If you want to set the time using the local time, useSetLocalTime()
.