How to convert from UTC to local time in C?

前端 未结 10 1691
无人共我
无人共我 2020-12-05 20:44

It\'s a simple question, but the solution appears to be far from simple. I would like to know how to convert from UTC to local time. I am looking for a solution in C that\'s

10条回答
  •  清歌不尽
    2020-12-05 21:16

    void   CTestDlg::OnBtnTest()   
    { 
    HANDLE   hFile; 
    WIN32_FIND_DATA   wfd; 
    SYSTEMTIME   systime; 
    FILETIME   localtime; 
    char   stime[32];     //
    memset(&wfd,   0,   sizeof(wfd)); 
    
    if((hFile=FindFirstFile( "F:\\VC\\MFC\\Test\\Release\\Test.exe ",        &wfd))==INVALID_HANDLE_VALUE) 
    { 
    char   c[2]; 
    DWORD   dw=GetLastError(); 
    wsprintf(c,   "%d ",   dw); 
    AfxMessageBox(c);   
    return   ;//
    } 
    FileTimeToLocalFileTime(&wfd.ftLastWriteTime,&localtime); 
    FileTimeToSystemTime(&localtime,&systime); 
    sprintf(stime, "%4d-%02d-%02d   %02d:%02d:%02d ", 
          systime.wYear,systime.wMonth,systime.wDay,systime.wHour, 
          systime.wMinute,systime.wSecond); 
    AfxMessageBox(stime);   
    } 
    

提交回复
热议问题