如何将日期字符串转换为time_t
How to convert date string to time_t
我试图将" 2018年2月13日星期二"转换为 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++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 复制列表初始化的隐式转换的等级是多少
- 正在将指针转换为范围
- 如何将 time-uuid(存储在 boost uuid 中)转换为时间戳/自纪元以来的时间?
- c/在Unix时间和"Gregorian time"之间转换
- 在 boost::p osix_time::p time 和 mongo::D ate_t 之间转换
- srand(time(null))导致编译器警告:隐式转换会丢失整数精度
- 使用自定义时区将 boost::p osix_time::p time 转换为字符串