错误日志:
{ [Error: Incorrect datetime value: ‘2012-08-24T17:29:11.683Z’ for
column ‘robot _refreshed_at’ at row 1] number: 1292,sqlStateMarker:
‘#’,sqlState: ‘22007’,message: ‘Incorrect datetime value:
\’2012-08-24T17:29:11.683Z\’ for column \’ robot_refreshed_at\’ at row
1′,sql: ‘INSERT INTO users
(ID,name,count_moments,count_likes,count_followers,rob
ot_refreshed_at,robot_count_followers) VALUES
(\’1834084\’,\’NNNyingzi\’,\’5\’,\
‘0\’,\’0\’,\’2012-08-24T17:29:11.683Z\’,\’0\’)’,setMaxListeners:
[Function],emit: [Function],addListener: [Function],on: [Function],
once: [Function],removeListener: [Function],removeAllListeners:
[Function],Listeners: [Function] }
我在Node.Js中使用这段代码
if s instanceof Date return s.toISOString()
并在数据库中更新它们.
sql插入表达式如下:
INSERT INTO users (ID,rob ot_refreshed_at,robot_count_followers) VALUES (\'1834084\',\'NNNyingzi\',\'5\',\ '0\',\'0\',\'2012-08-24T17:29:11.683Z\',\'0\')
我做错了吗?我只是从服务器中的表中使用phpmyadmin复制了一个表.
非常感谢.
最佳答案如Date and Time Literals所述:MysqL recognizes 07001 and 07002 values in these formats:
As a string in either
'YYYY-MM-DD HH:MM:SS'
or'YY-MM-DD HH:MM:SS'
format. A “relaxed” Syntax is permitted here,too: Any punctuation character may be used as the delimiter between date parts or time parts. For example,'2012-12-31 11:30:45'
,'2012^12^31 11+30+45'
,'2012/12/31 11*30*45'
,and'2012@12@31 11^30^45'
are equivalent.As a string with no delimiters in either
'YYYYMMDDHHMMSS'
or'YYMMDDHHMMSS'
format,provIDed that the string makes sense as a date. For example,'20070523091528'
and'070523091528'
are interpreted as'2007-05-23 09:15:28'
,but'071122129015'
is illegal (it has a nonsensical minute part) and becomes'0000-00-00 00:00:00'
.As a number in either
YYYYMMDDHHMMSS
orYYMMDDHHMMSS
format,provIDed that the number makes sense as a date. For example,19830905132800
and830905132800
are interpreted as'1983-09-05 13:28:00'
.A 07001 or 07002 value can include a trailing fractional seconds part in up to microseconds (6 digits) precision. Although this fractional part is recognized,it is discarded from values stored into 07001 or 07002 columns. For information about fractional seconds support in MysqL,see 07007.
您的日期字体’2012-08-24T17:29:11.683Z’不适合任何这些格式;建议你 –
>使用Node.Js Date对象的toLocaleFormat()
方法(确保MysqL连接的时区与Node.Js的语言环境的时区匹配):
if s instanceof Date return s.tolocaleFormat("%Y-%m-%d %H:%M:%s")
>使用Node.Js Date对象的valueOf()
方法获取自UNIX纪元以来的时间值(以毫秒为单位),除以1000(从UNIX纪元开始获得秒数)并通过MysqL的FROM_UNIXTIME()
函数. 总结
以上是内存溢出为你收集整理的ISO 8601 MySQL数据库时间戳:MySQL日期时间值不正确全部内容,希望文章能够帮你解决ISO 8601 MySQL数据库时间戳:MySQL日期时间值不正确所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)