std::filesystem::file_time_type
< 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> namespace fs = std::filesystem; using namespace std::chrono_literals; int main() { fs::path p = fs::current_path() / "example.bin"; std::ofstream(p.c_str()).put('a'); // 创建文件 auto ftime = fs::last_write_time(p); std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); // 对此演示假定为 system_clock // 注意: MSVC 上非真; C++20 将允许可移植的输出 std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n'; fs::last_write_time(p, ftime + 1h); // 向未来移动文件写入时间 1 小时 ftime = fs::last_write_time(p); // 从文件系统回读 cftime = decltype(ftime)::clock::to_time_t(ftime); std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n'; fs::remove(p); }
可能的输出:
File write time is Tue Mar 31 19:47:04 2015 File write time is Tue Mar 31 20:47:04 2015
参阅
(C++17) |
获取或设置最近一次数据修改的时间 (函数) |