c++ win32 获取进程启动时间

HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);
    if (process != NULL){
        FILETIME ftCreation, ftExit, ftKernel, ftUser;
        SYSTEMTIME stCreation, lstCreation;
        if (GetProcessTimes(process, &ftCreation, &ftExit, &ftKernel, &ftUser)) {
            FileTimeToSystemTime(&ftCreation, &stCreation);
            SystemTimeToTzSpecificLocalTime(NULL, &stCreation, &lstCreation);
        }
        CloseHandle(process);
    }
GetProcessTimes获取到的是FILETIME,然后转成SYSTEMTIME,SYSTEMTIME是格林威治时间,北京时间是UTC+8,所以转换出来的时间会比电脑看到的时间少8小时
SystemTimeToTzSpecificLocalTime可以将SYSTEMTIME转换成当前系统时区时间
posted @ 2020-09-30 14:30  YZHuang  阅读(1947)  评论(0编辑  收藏  举报