C++ 获取时间

代码

cpp 复制代码
std::string timp_point()
{
    auto high_res_now = std::chrono::high_resolution_clock::now();
    // 将高精度时钟的时间点转换为系统时钟的时间点
    auto now = std::chrono::time_point_cast<std::chrono::system_clock::duration>(high_res_now);
    // 转换为time_t类型
    std::time_t currentTime = std::chrono::system_clock::to_time_t(now);
    // 转换为本地时间
    std::tm *localTime = std::localtime(&currentTime);

    // 创建一个缓冲区来存储格式化的日期字符串
    char dateBuffer[100];
    // 使用strftime格式化日期

    std::strftime(dateBuffer, sizeof(dateBuffer), "%Y%m%dT%H%M%S", localTime);
    std::string time_p = dateBuffer;
    return time_p;
}
相关推荐
_w_z_j_4 分钟前
C++----模拟实现string
开发语言·c++
特立独行的猫a5 分钟前
redis客户端库redis++在嵌入式Linux下的交叉编译及使用
linux·数据库·c++·redis·redis客户端库
张槊哲7 分钟前
const(C++)
开发语言·c++
oioihoii12 分钟前
C++23 中 constexpr 的重要改动
c++·算法·c++23
沐知全栈开发29 分钟前
MongoDB 创建数据库
开发语言
pystraf1 小时前
UOJ 228 基础数据结构练习题 Solution
数据结构·c++·算法·线段树
ErizJ1 小时前
Golang | 迭代器模式
开发语言·golang·迭代器模式
牙痛不能吃糖,哭1 小时前
C++面试复习日记(8)2025.4.25,malloc,free和new,delete的区别
开发语言·c++
健康的猪1 小时前
golang的cgo的一点小心得
开发语言·后端·golang
夜夜敲码1 小时前
C语言教程(十六): C 语言字符串详解
c语言·开发语言