【发布时间】:2022-09-22 22:36:39
【问题描述】:
我正在使用 strptime() 将时间字符串转换为 *tm
这是我的代码
string ts(\"2023-12-30 22:50:50\");
struct tm ti;
strptime(ts, \"%F %T\", &ti);
std::cout << \"time string: \" << ts << endl
<< \"ti: \" << (ti.tm_year+1900) << \"-\" << (ti.tm_mon+1) << \"-\" << ti.tm_mday << \" \" << ti.tm_hour << \":\" << ti.tm_min << \":\" << ti.tm_sec << endl;
这是我得到的
time string: 2023-12-30 22:50:50
ti: 2023-12-30 21:50:50
有关更多信息:我的时区应该是 -0600(美国中心时间),但是当我使用 \"date \'+%Y-%m-%d %H:%M:%S %z\ 显示时,它会显示 -0500 ”。我认为这是由夏令时引起的。我错了吗?但是 2023-12-30 不是夏令时。
-
什么时区?无论如何,请提供minimal reproducible example。
-
我收到
error: cannot convert \'std::string\' {aka \'std::__cxx11::basic_string<char>\'} to \'const char*\'。你能发一个minimal reproducible example吗? -
对不起这是我的错。我的原始代码是
strptime(ts.c_str(), \"%F %T\", &ti);我在输入时忘记了 .c_str()。