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 起) | |
表示文件时间。
|
(C++20 前) |
示例
运行此代码
#include <iostream> #include <chrono> #include <iomanip> #include <fstream> #include <filesystem> using namespace std::chrono_literals; int main() { auto p = std::filesystem::temp_directory_path() / "example.bin"; std::ofstream(p.c_str()).put('a'); // 创建文件 auto print_last_write_time = [](std::filesystem::file_time_type const& ftime) { std::time_t cftime = std::chrono::system_clock::to_time_t( std::chrono::file_clock::to_sys(ftime)); std::cout << "File write time is " << std::asctime(std::localtime(&cftime)); }; auto ftime = std::filesystem::last_write_time(p); print_last_write_time(ftime); std::filesystem::last_write_time(p, ftime + 1h); // 向未来移动文件时间 1 小时 ftime = std::filesystem::last_write_time(p); // 从文件系统回读 print_last_write_time(ftime); std::filesystem::remove(p); }
可能的输出:
File write time is Sun May 9 23:29:58 2021 File write time is Mon May 10 00:29:58 2021
参阅
(C++17) |
获取或设置最近一次数据修改的时间 (函数) |