std::filesystem::file_time_type
来自 cppreference.com
< cpp | filesystem
在头文件中定义 <filesystem> |
||
using file_time_type = std::chrono::time_point</*trivial-clock*/>; |
(自 C++17) (直至 C++20) |
|
using file_time_type = std::chrono::time_point<std::chrono::file_clock>; |
(自 C++20) | |
表示文件时间。
/*trivial-clock*/ 是一个实现定义的类型,满足 TrivialClock 并且足以表示文件系统提供的文件时间值的精度和范围。 |
(直至 C++20) |
[编辑] 示例
运行此代码
#include <chrono> #include <filesystem> #include <format> #include <fstream> #include <iostream> using namespace std::chrono_literals; int main() { auto p = std::filesystem::temp_directory_path() / "example.bin"; std::ofstream{p.c_str()}.put('a'); // create file std::filesystem::file_time_type ftime = std::filesystem::last_write_time(p); std::cout << std::format("File write time is {}\n", ftime); // move file write time 1 hour to the future std::filesystem::last_write_time(p, ftime + 1h); // read back from the filesystem ftime = std::filesystem::last_write_time(p); std::cout << std::format("File write time is {}\n", ftime); std::filesystem::remove(p); }
可能的输出
File write time is 2023-09-04 19:33:24.702639224 File write time is 2023-09-04 20:33:24.702639224
[编辑] 另请参阅
(C++17) |
获取或设置最后一次数据修改的时间 (函数) |