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;
}
相关推荐
奇树谦5 小时前
LRU 缓存原理与 C++ 实践示例
开发语言·c++·缓存
toooooop85 小时前
FastAdmin Hook 机制与插件错误透传:`$result` 之外的信封
开发语言·fastadmin
小马过河R5 小时前
EdgeOne深度解析:从原理、适用场景到COS接入的技术逻辑
java·开发语言·前端·spring·cos
多弗朗皮卡丘5 小时前
C++ 红黑树
开发语言·c++·红黑树
ZoeLandia6 小时前
TypeScript 04:类型断言与类型守卫
开发语言·前端·typescript
geovindu6 小时前
rust: pool Pattern
开发语言·后端·设计模式·rust·对象池简写模式
曼巴UE56 小时前
UE 属性同步
网络·c++·ue5
无忧.芙桃6 小时前
图的精髓:邻接矩阵与遍历全解析
c++·算法·面试·深度优先·广度优先
jimy16 小时前
标准的动态类型定义与“多态”无关,非多态对象同样会出现动态类型不同于静态类型的情形
开发语言·c++
冬、不眠的夜6 小时前
Nuitka 将 python 程序编译成 exe 指南
开发语言·python