std::filesystem::file_time_type
文件系统::file[医]时间[医]类型
Defined in header | | |
---|---|---|
using file_time_type = std::chrono::time_point</*trivial-clock*/>; | | (since C++17) |
表示文件时间。trivial-clock
是满足以下条件的实现定义类型。TrivialClock
并且足以表示文件系统提供的文件时间值的分辨率和范围。
例
二次
#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' // 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
二次
另见
last_write_time (C++17) | gets or sets the time of the last data modification (function) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。