如何将字符串(2019年10月3日星期四18:45:10)转换为cpp中的time_t格式?
How to convert string ( Thu Oct 3 18:45:10 2019) to time_t format in cpp?
将该时间格式存储在其他文件中。并将其检索为字符串。如何再次将其更改为时间格式。
您可以使用strptime
来分析时间,然后mktime
将其转换为time_t
const char *time_details = "Thu Oct 3 18:45:10 2019";
struct tm tm;
// %a or %A
// The weekday name according to the current locale, in abbreviated form or the full name.
// %b or %B or %h
// The month name according to the current locale, in abbreviated form or the full name.
// the field descriptors must match the string format you are providing.
strptime(time_details, "%a %b %d %H:%M:%S %Y", &tm);
time_t t = mktime(&tm);
您可以在 strptime(3( 找到输入字段描述符的详细用法
相关文章:
- 从 'int' 到 'int*' CPP 的转换无效
- 主.cpp:18:20:错误:从"int*"转换为"int"会失去精度 [-fa
- 不要使用静态强制转换进行算术转换(cpp-core-guidelines)
- 将模板类转换为标头和 cpp 文件
- 将strcpy_s转换为稳定的CPP
- 如何大致将 cpp 代码结构转换为 python
- Antlr cpp 运行时 任何错误的指针转换?
- 我想使用 std::stoi 函数在 cpp 中将字符串转换为整数,因为我想在字符串中找到不同数字的总和(在下级酶中)
- 从 cpp lib 调用函数时的数据类型转换
- 时间转换为 24 小时格式 cpp
- 如何将字符串(2019年10月3日星期四18:45:10)转换为cpp中的time_t格式?
- uint8_t转换 (CPP) 上的分段错误
- 如何在 CPP 中将 Typedef basic_string字符串转换为<char>字节数组
- 是否可以将信息从XML文件转换为CPP
- CPP Windows 字符串转换混淆了 CStringA 和 LPCWSTR
- Lambda在CPP中转换为NULLPTR
- 将代码从 JS 转换为 CPP
- 为什么不将.cpp转换为c程序文件呢
- 如何将perl+cpp转换为独立的应用程序
- 将luacov/luacov.cpp转换为Lua模块