std::filesy...le_time_type(3)
π
std::filesystem::file_time_type β the C++ Standard Library tea (from the std::filesy...le_time_type(3) page)
okay so bestie, welcome to the manual page for std::filesystem::file_time_type β yeah the header got truncated in the terminal and it's giving "my name is a mystery" but it's literally std::filesystem::file_time_type from the C++ Standard Library. no cap. let's get into it π
β¨ NAME β¨
std::filesystem::file_time_type β and yes that's literally the whole name section, std::filesystem::file_time_type. iconic, no notes. π
πΈ SYNOPSIS πΈ
okay so here's the whole vibe, and the way it's defined changed in C++20 so pay attention bestie:
Defined in the header <filesystem>:
using file_time_type = std::chrono::time_point</*trivial-clock*/>;
(since C++17) β and also (until C++20) because this version is only valid up to that point.
then, starting in C++20, it becomes:
using file_time_type =
std::chrono::time_point<std::chrono::file_clock>;
(since C++20) π¦
π DESCRIPTION π
literally what it says on the tin: it Represents file time. that's the whole job. main character energy tbh. β¨
and about that mysterious trivial-clock β bestie it's an implementation-defined type, meaning your implementation gets to pick it, and it satisfies TrivialClock and is sufficient to represent the resolution and range of the file time values offered by the filesystem. that whole trivial-clock explanation is (until C++20), so once you're on C++20 it's std::chrono::file_clock and we move on π
π EXAMPLE π
fr fr the code says // Run this code at the top, so here's the whole thing verbatim, don't touch anything:
#include <chrono>
#include <filesystem>
#include <format>
#include <fstream>
#include <iostream>
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::cout << std::format("File write time is {}\n", 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::cout << std::format("File write time is {}\n", ftime);
std::filesystem::remove(p);
}
β Possible output
no cap, this is what it can spit out:
File write time is 2023-09-04 19:33:24.702639224
File write time is 2023-09-04 20:33:24.702639224
see that? one hour apart. the 1h moved it, periodt. π
π¦ SEE ALSO π¦
last_write_timeβ gets or sets the time of the last data modification(C++17)(function)π
ngl this one's short and sweet, but don't sleep on it β this type is literally how your filesystem timestamps get stored, so treat it with respect π«Ά
okay bye bestie, mwah ππ
β this page came from http://cppreference.com, dated 2024.06.10, and the footer title was std::filesy...le_time_type(3) (truncated again, we love that for us π). go touch some files. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms