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;
}
相关推荐
感哥3 小时前
C++ 多态
c++
沐怡旸10 小时前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River41613 小时前
Javer 学 c++(十三):引用篇
c++·后端
感哥16 小时前
C++ std::set
c++
侃侃_天下16 小时前
最终的信号类
开发语言·c++·算法
博笙困了17 小时前
AcWing学习——差分
c++·算法
echoarts17 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix17 小时前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
青草地溪水旁17 小时前
设计模式(C++)详解—抽象工厂模式 (Abstract Factory)(2)
c++·设计模式·抽象工厂模式
青草地溪水旁17 小时前
设计模式(C++)详解—抽象工厂模式 (Abstract Factory)(1)
c++·设计模式·抽象工厂模式