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;
}
相关推荐
十五年专注C++开发1 分钟前
hiredis: 一个轻量级、高性能的 C 语言 Redis 客户端库
开发语言·数据库·c++·redis·缓存
WJ.Polar2 分钟前
Python数据容器-集合set
开发语言·python
晓13133 分钟前
JavaScript加强篇——第七章 浏览器对象与存储要点
开发语言·javascript·ecmascript
nbsaas-boot26 分钟前
Go语言生态成熟度分析:为何Go还无法像Java那样实现注解式框架?
java·开发语言·golang
hi0_629 分钟前
03 数组 VS 链表
java·数据结构·c++·笔记·算法·链表
xiaocainiao88136 分钟前
Python 实战:构建可扩展的命令行插件引擎
开发语言·python
碧海蓝天20221 小时前
C++法则21:避免将#include放在命名空间内部。
开发语言·c++
兮动人1 小时前
Java应用全链路故障排查实战指南:从系统资源到JVM深度诊断
java·开发语言·jvm
R-sz1 小时前
导出word并且插入图片
开发语言·c#·word
CodeWithMe1 小时前
【读书笔记】《C++ Software Design》第一章《The Art of Software Design》
开发语言·c++