std::experimental::filesystem::file_time_type
来自 cppreference.com
< cpp | experimental | fs
定义在头文件 <experimental/filesystem> 中 |
||
using file_time_type = chrono::time_point</*trivial-clock*/>; |
(文件系统 TS) | |
表示文件时间。trivial-clock
是一个实现定义的类型,它满足 TrivialClock 并且足以表示文件系统提供的文件时间值的精度和范围。
[编辑] 示例
运行此代码
#include <chrono> #include <experimental/filesystem> #include <fstream> #include <iomanip> #include <iostream> namespace fs = std::experimental::filesystem; using namespace std::chrono_literals; int main() { fs::path p = fs::current_path() / "example.bin"; std::ofstream(p.c_str()).put('a'); // create file auto ftime = fs::last_write_time(p); std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); // assuming system_clock std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n'; fs::last_write_time(p, ftime + 1h); // move file write time 1 hour to the future ftime = fs::last_write_time(p); // read back from the filesystem 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
[编辑] 另请参见
获取或设置最后数据修改时间 (函数) |