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;
}
相关推荐
clint4563 天前
C++进阶(1)——前景提要
c++
夜悊3 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴3 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0013 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
LDR0064 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术4 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园4 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob4 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享4 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.4 天前
C语言--day30
c语言·开发语言