Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++;localtime到mysql日期时间 我有一个C++时间倍,它记录自1970年1月1日以来的秒。_C++_Mysql_Datetime - Fatal编程技术网

c++;localtime到mysql日期时间 我有一个C++时间倍,它记录自1970年1月1日以来的秒。

c++;localtime到mysql日期时间 我有一个C++时间倍,它记录自1970年1月1日以来的秒。,c++,mysql,datetime,C++,Mysql,Datetime,我想转换这个double并将其存储在MySQL数据库中,因此下面是我的代码,首先将其转换为datetime格式:*注意:ss.time是double /* do the time conversion */ time_t rawtime; struct tm * timeinfo; rawtime = (time_t)ss.time; timeinfo = localtime(&rawtime); 此代码将其转换为以下格式:Thu Jul 24 05:45:07 1947 然后,我尝试

我想转换这个double并将其存储在MySQL数据库中,因此下面是我的代码,首先将其转换为datetime格式:*注意:ss.time是double

/* do the time conversion */
time_t rawtime;
struct tm * timeinfo;
rawtime = (time_t)ss.time;
timeinfo = localtime(&rawtime);
此代码将其转换为以下格式:Thu Jul 24 05:45:07 1947

然后,我尝试将其写入MySQL数据库,如下所示:

string theQuery = "UPDATE readings SET chng = 1, time = CAST('";
theQuery += boost::lexical_cast<string>(asctime(timeinfo));
theQuery += "' AS DATETIME) WHERE id = 1";
string theQuery=“更新读数集chng=1,time=CAST(”;
查询+=boost::词法转换(asctime(timeinfo));
查询+=“'作为日期时间),其中id=1”;
它不起作用,但使用NULL更新表中的time DATETIME变量


有人能告诉我如何正确的转换和更新SQL表吗?< /p> < p>你的C++双是一个标准的UNIX时间戳,MySQL可以用它的函数转换:

UDPATE ... SET ... time=FROM_UNIXTIME(rawtime)

出于某些原因,当我尝试使用FROM_UNIXTIME()进行更新并将3586767203放入括号中(即读取时间)时,字段中会输入null?mysql仅支持32位unix时间,在2038年初达到最大值。你的TimesTamp在2083年8月,远远超出了限制。