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;
}
相关推荐
逝水无殇11 分钟前
C# 多态性详解
开发语言·后端·c#
逝水无殇12 分钟前
C# 继承(Inheritance)详解
开发语言·后端·c#
多加点辣也没关系19 分钟前
JavaScript|第6章:流程控制语句
开发语言·前端·javascript
foundbug99939 分钟前
Polar Code 编解码 MATLAB 实现
开发语言·算法·matlab
李小小钦1 小时前
D. Storming Arasaka(Codeforces 2238)
c语言·开发语言·数据结构·c++·算法
W是笔名1 小时前
python___容器类型的数据___列表
开发语言·windows·python
跨境数据猎手1 小时前
多平台电商比价系统从零搭建合规
开发语言·爬虫·架构
卷无止境1 小时前
SFML 深度解读:一个教科书级 C++ 多媒体库的内功心法
c++·后端
hai3152475431 小时前
九章编译法:DEEPSEEK V3.2汇编编译实例
java·开发语言
lkshop1 小时前
Next.js 网站 SEO 优化:从 SSR、Sitemap 到结构化数据
开发语言·javascript·ecmascript