Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将字符串转换为文件时间_C++ - Fatal编程技术网

C++ 将字符串转换为文件时间

C++ 将字符串转换为文件时间,c++,C++,转换格式为“1997-01-08 03:04:01:463”的字符串的最快方法是什么 要申报时间吗? 有没有这样的函数?假设您在windows上,字符串看起来像SYSTEMTIME,并且有一个名为SystemTimeToFileTime的例程将其转换为FILETIME。当然,您仍然需要自己处理标记化和整数解析。假设您在windows上,字符串看起来像SYSTEMTIME,并且有一个名为SystemTimeToFileTime的例程,将其转换为FILETIME。当然,您仍然需要自己处理标记化和整数

转换格式为“1997-01-08 03:04:01:463”的字符串的最快方法是什么 要申报时间吗?
有没有这样的函数?

假设您在windows上,字符串看起来像SYSTEMTIME,并且有一个名为SystemTimeToFileTime的例程将其转换为FILETIME。当然,您仍然需要自己处理标记化和整数解析。

假设您在windows上,字符串看起来像SYSTEMTIME,并且有一个名为SystemTimeToFileTime的例程,将其转换为FILETIME。当然,您仍然需要自己处理标记化和整数解析。

既然您提到了FILETIME,我想您指的是Windows,因为*nix不像Windows那样区分文件时间和系统时间(vs.)。不幸的是,在这两种情况下,您都不走运,因为没有快捷方式可以使用系统调用或标准C/C++库调用将此类字符串转换为Windows中的
FILETIME
结构或*nix中的
time\t


为了走运,您很可能必须使用包装器库,例如。

因为您提到了文件时间,我想您指的是Windows,因为*nix不像Windows那样区分文件时间和系统时间(vs.)。不幸的是,在这两种情况下,您都不走运,因为没有快捷方式可以使用系统调用或标准C/C++库调用将此类字符串转换为Windows中的
FILETIME
结构或*nix中的
time\t


为了获得幸运,您很可能必须使用包装器库,例如。

我猜您指的是Windows FILETIME,它包含自1/1/1600以来的100纳秒刻度数

  • 使用sscanf()或std::istringstream将字符串解析为其组件。 并填充SYSTEMTIME结构
  • 使用SystemTimeToFileTime()转换为FILETIME
  • e、 g


    我猜你说的是Windows FILETIME,它包含自1/1/1600以来的100纳秒刻度

  • 使用sscanf()或std::istringstream将字符串解析为其组件。 并填充SYSTEMTIME结构
  • 使用SystemTimeToFileTime()转换为FILETIME
  • e、 g

    你是说a吗?你是说a吗?
    FILETIME DecodeTime(const std::string &sTime)
    {
        std::istringstream istr(sTime);
        SYSTEMTIME st = { 0 };
        FILETIME ft = { 0 };
    
        istr >> st.wYear;
        istr.ignore(1, '-');
        istr >> st.wMonth;
        istr.ignore(1, '-');
        istr >> st.wDay;
        istr.ignore(1, ' ');
        istr >> st.wHour;
        istr.ignore(1, ':');
        istr >> st.wMinute;
        istr.ignore(1, ':');
        istr >> st.wSecond;
        istr.ignore(1, '.');
        istr >> st.wMilliseconds;
    
        // Do validation that istr has no errors and all fields 
        // are in sensible ranges
        // ...
    
        ::SystemTimeToFileTime(&st, &ft);
        return ft;
    }
    
    int main(int argc, char* argv[])
    {
        FILETIME ft = DecodeTime("1997-01-08 03:04:01.463");
        return 0;
    }