Defined in header <filesystem> | ||
---|---|---|
using file_time_type = std::chrono::time_point</*trivial-clock*/>; | (since C++17) (until C++20) | |
using file_time_type = std::chrono::time_point<std::chrono::file_clock>; | (since C++20) |
Represents file time.
| (until C++20) |
#include <chrono> #include <filesystem> #include <fstream> #include <iostream> #include <print> 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::println("File write time is {}", 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::println("File write time is {}", ftime); std::filesystem::remove(p); }
Possible output:
File write time is Sun May 9 23:29:58 2021 File write time is Mon May 10 00:29:58 2021
(C++17) | gets or sets the time of the last data modification (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/filesystem/file_time_type