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;
}
相关推荐
我命由我123453 分钟前
嵌入式 STM32 开发问题:烧录 STM32CubeMX 创建的 Keil 程序没有反应
c语言·开发语言·c++·stm32·单片机·嵌入式硬件·嵌入式
筏.k23 分钟前
C++: 类 Class 的基础用法
android·java·c++
C++ 老炮儿的技术栈37 分钟前
手动实现strcpy
c语言·开发语言·c++·算法·visual studio
一条叫做nemo的鱼40 分钟前
从汇编的角度揭开C++ this指针的神秘面纱(下)
java·汇编·c++·函数调用·参数传递
Joomla中文网1 小时前
joomla5去掉后台PHP版本警告信息
开发语言·php
大磕学家ZYX1 小时前
使用Nodejs尝试小程序后端服务编写:简单的待办事项管理demo
开发语言·javascript·小程序·node.js
先做个垃圾出来………1 小时前
什么是装饰器?
开发语言·python
ComputerInBook1 小时前
理解 C++ 的 this 指针
开发语言·c++·指针·this·this指针
我真不会起名字啊1 小时前
Qt如何生成和使用DLL动态链接库
开发语言·qt
MikeWe2 小时前
一文读懂C++移动语义和完美转发
c++