无法将带有秒数的字符串转换为从epoch转换为date_time
Unable to convert string with seconds from epoch to date_time
我有一个字符串,其中包含来自时期的秒,如何将此字符串转换为格式
因此 -
年度HH:MM:SS
这里的月份应显示月号和日期。同样需要以24小时格式的时间。
例如:
2019-06-26 11:14:25
我曾尝试使用strptime,但还没有成功,有人可以帮助我做错了什么。
这是我到目前为止尝试的
int main()
{
string timee = "12341234534";
const char *ptr = timee.c_str();
struct tm tim;
strptime(ptr, "%S", &tim);
time_t abcd = mktime(&tim);
cout<<abcd;
return 0;
}
在另一个stackoverflow链接上找到此代码段如何将包含时间的字符串变量转换为time_t类型C ?
您的问题有些混乱,但我想我想出了您想要什么...
如果时间是time_t
兼容格式,则只需将其直接读取到time_t
变量中,然后通过std::localtime
转换它,以便您可以使用std::put_time
以通缉格式输出它。
std::time_t time;
std::cin >> time;
std::cout << std::put_time(std::localtime(&time), "%F %T") << 'n';
相关文章:
- 防止主数据类型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个独立图像
- 复制列表初始化的隐式转换的等级是多少
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 无法将带有秒数的字符串转换为从epoch转换为date_time
- 如何将EPOCH时间转换为时间格式(hh:mm)
- C/C++时区正确的时间转换(从epoch到秒)
- 将格式为20160120的日期转换为自epoch以来的天数
- 自unix epoch以来,将日期,时间和UTC偏移值转换为毫秒