C++ Time returned is two hours out

后端 未结 2 954
天涯浪人
天涯浪人 2021-01-22 13:15

Bit of a c++ newbie so here we go;

I have a method that is parsing a date/time, however that date/time is passed to me always with 00:00:00 as the hh:mm:ss. As such i wa

2条回答
  •  暖寄归人
    2021-01-22 13:35

    Try this function:

    CTime Time2UTC(CTime original)
    {
        CString Formatted = original.FormatGmt(L"%Y%m%d%H%M%S");
        int Year, Month, Day, Hour, Minute;
        if (Formatted != L"" && Formatted.GetLength() >= 12)
        {
            Year = _wtol(Formatted.Left(4));
            Month = _wtol(Formatted.Mid(4, 2));
            Day = _wtol(Formatted.Mid(6,2));
            Hour = _wtol(Formatted.Mid(8, 2));
            Minute = _wtol(Formatted.Mid(10, 2));
            CTime result(Year, Month, Day, Hour, Minute, 0);
            return result;
        }
        else
            return (CTime)NULL;
    }
    

提交回复
热议问题