【发布时间】:2013-09-27 14:35:16
【问题描述】:
我有一个自 1970 年 1 月 1 日以来记录秒数的 c++ 时间双倍。
我想转换这个双精度并将其存储在 MySQL 数据库中,所以这是我首先将其转换为日期时间格式的代码:*注意:ss.time 是双精度..
/* 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";
它不起作用,而是将表中的时间 DATETIME 变量更新为 NULL。
谁能告诉我如何进行正确的转换和更新 SQL 表?
【问题讨论】: