C++ 参考手册
- C++11
- C++14
- C++17
- C++20
- C++ 编译器支持情况表
- 独立与宿主实现
- C++ 语言
- C++ 关键词
- 预处理器
- C++ 标准库头文件
- 具名要求
- 功能特性测试 (C++20)
- 工具库
- 类型支持(基本类型、RTTI、类型特性)
- 概念库 (C++20)
- 错误处理
- 动态内存管理
- 日期和时间工具
- 字符串库
- 容器库
- 迭代器库
- 范围库 (C++20)
- 算法库
- 数值库
- 输入/输出库
- 文件系统库
- std::filesystem::path
- std::filesystem::filesystem_error
- std::filesystem::directory_entry
- std::filesystem::directory_iterator
- std::filesystem::file_time_type
- std::filesystem::recursive_directory_iterator
- std::filesystem::file_status
- std::filesystem::space_info
- std::filesystem::file_type
- std::filesystem::perms
- std::filesystem::perm_options
- std::filesystem::copy_options
- std::filesystem::directory_options
- std::filesystem::absolute
- std::filesystem::canonical, std::filesystem::weakly_canonical
- std::filesystem::relative, std::filesystem::proximate
- std::filesystem::copy
- std::filesystem::copy_file
- std::filesystem::copy_symlink
- std::filesystem::create_directory, std::filesystem::create_directories
- std::filesystem::create_hard_link
- std::filesystem::create_symlink, std::filesystem::create_directory_symlink
- std::filesystem::current_path
- std::filesystem::exists
- std::filesystem::equivalent
- std::filesystem::file_size
- std::filesystem::hard_link_count
- std::filesystem::last_write_time
- std::filesystem::permissions
- std::filesystem::read_symlink
- std::filesystem::remove, std::filesystem::remove_all
- std::filesystem::rename
- std::filesystem::resize_file
- std::filesystem::space
- std::filesystem::status, std::filesystem::symlink_status
- std::filesystem::temp_directory_path
- std::filesystem::is_block_file
- std::filesystem::is_character_file
- std::filesystem::is_directory
- std::filesystem::is_empty
- std::filesystem::status_known
- std::filesystem::is_fifo
- std::filesystem::is_other
- std::filesystem::is_regular_file
- std::filesystem::is_socket
- std::filesystem::is_symlink
- 注释
- 本地化库
- 正则表达式库
- 原子操作库
- 线程支持库
- 实验性 C++ 特性
- 有用的资源
- 索引
- std 符号索引
- 协程支持 (C++20)
- 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 起) | |
表示文件时间。
|
(C++20 前) |
示例
运行此代码
#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'); // 创建文件 auto ftime = fs::last_write_time(p); std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); // 对此演示假定为 system_clock // 注意: MSVC 上非真; C++20 将允许可移植的输出 std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n'; fs::last_write_time(p, ftime + 1h); // 向未来移动文件写入时间 1 小时 ftime = fs::last_write_time(p); // 从文件系统回读 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
参阅
(C++17) |
获取或设置最近一次数据修改的时间 (函数) |