Spec-Zone.ru › C++

std::filesystem::file_time_type

Определён в заголовочном файле <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)

Представляет время файла.

/*trivial-clock*/ — это определяемый реализацией тип, удовлетворяющий требованиям TrivialClock и обеспечивающий достаточные разрешение и диапазон для представления значений времени файла, поддерживаемых файловой системой.

(до C++20)

Пример

#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);
}

Возможный вывод:

File write time is 2023-09-04 19:33:24.702639224
File write time is 2023-09-04 20:33:24.702639224

См. также

last_write_time
(C++17)
получает или задаёт время последнего изменения данных
(функция)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/filesystem/file_time_type

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API