【问题标题】:How do I set the windows system clock to the right local time using C++?如何使用 C++ 将 Windows 系统时钟设置为正确的本地时间?
【发布时间】:2023-04-03 16:49:01
【问题描述】:

现在我做这样的事情:

    SYSTEMTIME st;

    st.wHour = 6;
    st.wMinute = 23;

    BOOL result = SetSystemTime(&st);

目标是让它在我的本地机器上显示准确的时间。当我运行程序时,它会将其更改为 8:23 而不是 6:23。如何让它显示正确的当地时间?

【问题讨论】:

    标签: c++ windows winapi systemtime


    【解决方案1】:

    SetSystemTime() 期望提供的时间为 UTC。如果您想使用当地时间设置时间,请使用SetLocalTime()

    【讨论】:

    • 感谢这工作。我还需要先使用 GetLocalTime(&st),然后在调用 SetLocalTime(&st) 之前对其进行修改。非常感谢
    猜你喜欢
    • 2011-08-30
    • 1970-01-01
    • 2010-11-28
    • 2017-05-27
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多