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;
}
相关推荐
软件黑马王子2 小时前
C#初级教程(4)——流程控制:从基础到实践
开发语言·c#
闲猫2 小时前
go orm GORM
开发语言·后端·golang
黑不溜秋的3 小时前
C++ 设计模式 - 策略模式
c++·设计模式·策略模式
李白同学4 小时前
【C语言】结构体内存对齐问题
c语言·开发语言
黑子哥呢?5 小时前
安装Bash completion解决tab不能补全问题
开发语言·bash
青龙小码农5 小时前
yum报错:bash: /usr/bin/yum: /usr/bin/python: 坏的解释器:没有那个文件或目录
开发语言·python·bash·liunx
大数据追光猿5 小时前
Python应用算法之贪心算法理解和实践
大数据·开发语言·人工智能·python·深度学习·算法·贪心算法
Dream it possible!5 小时前
LeetCode 热题 100_在排序数组中查找元素的第一个和最后一个位置(65_34_中等_C++)(二分查找)(一次二分查找+挨个搜索;两次二分查找)
c++·算法·leetcode
柠石榴5 小时前
【练习】【回溯No.1】力扣 77. 组合
c++·算法·leetcode·回溯
王老师青少年编程5 小时前
【GESP C++八级考试考点详细解读】
数据结构·c++·算法·gesp·csp·信奥赛