gpt4 book ai didi

c++ - C++ 中的错误时间

转载 作者:可可西里 更新时间:2023-11-01 13:27:48 25 4
gpt4 key购买 nike

// Simple program to get the date and time on Windows
// It compiles and works fine but displays the wrong hour!


// Using Visual C++ 2008 Express on XP SP2
#include <Windows.h>
#include <iostream>
using namespace std;


void main()
{
SYSTEMTIME st;
GetSystemTime(&st);

cout << "Year : " << st.wYear << "\n";
cout << "Month : " << st.wMonth << "\n";
cout << "Day : " << st.wDay << "\n";

// The following line displays the wrong hour, off by 4 hours.
// What gives?
cout << "Hour : " << st.wHour << "\n";
cout << "Minute : " << st.wMinute << "\n";
cout << "Second : " << st.wSecond << "\n";
}

// TIA guys!
// -- Bert

最佳答案

根据文档,时间为 UTC。链接 HERE

你想要的本地时间 GetLocalTime()

关于c++ - C++ 中的错误时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/821490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com