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;
}
相关推荐
FQNmxDG4S21 小时前
Java多线程编程:Thread与Runnable的并发控制
java·开发语言
前端老石人21 小时前
HTML 字符引用完全指南
开发语言·前端·html
matlab_xiaowang1 天前
Redux 入门:JavaScript 可预测状态管理库
开发语言·javascript·其他·ecmascript
虹科网络安全1 天前
艾体宝干货|数据复制详解:类型、原理与适用场景
java·开发语言·数据库
axng pmje1 天前
Java语法进阶
java·开发语言·jvm
汉克老师1 天前
GESP2025年3月认证C++五级( 第三部分编程题(1、平均分配))
c++·算法·贪心算法·排序·gesp5级·gesp五级
老前端的功夫1 天前
【Java从入门到入土】28:Stream API:告别for循环的新时代
java·开发语言·python
qq_435287921 天前
第9章 夸父逐日与后羿射日:死循环与进程终止?十个太阳同时值班的并行冲突
java·开发语言·git·死循环·进程终止·并行冲突·夸父逐日
止语Lab1 天前
从手动到框架:Go DI 演进的三个拐点
开发语言·后端·golang
yaoxin5211231 天前
397. Java 文件操作基础 - 创建常规文件与临时文件
java·开发语言·python