我有一个定义为TIMESTAMP的MYSQL列。

每当我用javascript new Date()创建一行时,该值就可以正常存储,没有任何问题。

但是,当我想更新值,在该列上发送相同的new Date()时,出现错误

Error: ER_TRUNCATED_WRONG_VALUE: Incorrect datetime value: '2017-06-16T17:35:34.377Z' for column 'last_access'.

我可以将整个事情管理为Datetime并相应地设置日期格式以解决错误,但是我想了解为什么会发生错误。

最佳答案

MariaDB的日期格式必须类似于“YYYY-MM-DD HH:MM:SS”。

如果要使用JS插入日期,请​​尝试创建自己的字符串。

const newDate: Date = new Date();
const dd = newDate.getDate();
const number = newDate.getMonth() + 1; // month start at 0, we have to add 1.
const yyyy = newDate.getUTCFullYear();

const insertString = `${yyyy}-${mm}-${dd}`;

09-10 09:15
查看更多