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;
}
相关推荐
always_TT15 分钟前
C语言中的字符与字符串(char数组)
c语言·开发语言
forAllforMe34 分钟前
LAN9252 从机寄存器配置--C语言举例
c语言·开发语言
weixin_537590451 小时前
《C程序设计语言》练习答案(练习1-4)
c语言·开发语言
chushiyunen1 小时前
python中的内置属性 todo
开发语言·javascript·python
麦麦鸡腿堡1 小时前
JavaWeb_请求参数,设置响应数据,分层解耦
java·开发语言·前端
2301_819414302 小时前
C++与区块链智能合约
开发语言·c++·算法
不想看见4042 小时前
Valid Parentheses栈和队列--力扣101算法题解笔记
开发语言·数据结构·c++
炸膛坦客2 小时前
单片机/C/C++八股:(十五)内存对齐、结构体内存对齐
c语言·开发语言·单片机
老约家的可汗2 小时前
C/C++内存管理探秘:从内存分布到new/delete的底层原理
c语言·c++
娇娇yyyyyy2 小时前
QT编程(13): Qt 事件机制eventfilter
开发语言·qt