gpt4 book ai didi

c++ - 如何将日期字符串转换为 time_t

转载 作者:行者123 更新时间:2023-11-28 01:37:09 26 4
gpt4 key购买 nike

我正在尝试将“Tue Feb 13 00:26:36 2018”转换为 time_t,我该怎么做,我尝试寻找一个函数但找不到。这是使用非托管 C++。

最佳答案

如果你使用的是 C++11,你可以这样做。

#include <iostream>
#include <iomanip>
#include <ctime>
#include <sstream>

int main()
{
struct tm tm;
std::istringstream iss("Tue Feb 13 00:26:36 2018");
iss >> std::get_time(&tm, "%a %b %d %H:%M:%S %Y");
time_t time = mktime(&tm);

std::cout << time << std::endl;
return 0;
}

关于c++ - 如何将日期字符串转换为 time_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48800745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com