11 月 30 日 -0001 返回时间戳
在有人说是这样之前,我检查了其他类似的问题,但无济于事。基本上,我从数据库中获取时间戳并显示它,这是用于检索的代码:
while($row = mysql_fetch_array($result)) {
$timestamp = date("l F d Y", strtotime($row['timestamp']));
}
这是提交时的代码:
$sql = "INSERT INTO mysql_table (timestamp) VALUES (now())";
我认为这将是一个简单的格式错误(因此是 strtotime),但事实并非如此不工作,如您所见: http://aviatex14.co.uk/anonpost/index.php< /a>
我可以将其更改为:
$date = date("l F d Y", $row['timestamp']);
并获取 1969 年 12 月 31 日,但这也没有帮助..
哦,我的列数据类型是日期时间。
任何帮助将不胜感激! :)
Before anyone say's it, I checked other questions like this, but to no avail. Basically, I'm taking a timestamp from my DB and displaying it, here's the code for retrieval:
while($row = mysql_fetch_array($result)) {
$timestamp = date("l F d Y", strtotime($row['timestamp']));
}
And here is the code for when it is submitted:
$sql = "INSERT INTO mysql_table (timestamp) VALUES (now())";
I thought it would be a simple formatting error (thus the strtotime) but that didn't work as you can see: http://aviatex14.co.uk/anonpost/index.php
I can change it to:
$date = date("l F d Y", $row['timestamp']);
and get December 31st 1969, but that's not heplful either..
Oh, my column data type is datetime.
Any help would be much appreciated! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须在单词
timestamp
两边加上反引号,因为这是一个保留字。You have to put backticks around the word
timestamp
as this is a reserved word.如果您打算在 PHP 中进行日期格式化,那么只需从 MySQL 获取 UNIX_TIMESTAMP,它可以直接用作 PHP 时间戳:
您的
date(... $row['timestamp'])< /code> 失败,因为 date() 函数需要一个 TIME VALUE,它只是一个 unix 时间戳 - 您传递的是日期的字符串表示形式,它很可能会转换为
0
,这是简1/1970 00:00,然后根据时区进行调整,因此您会得到 Dec 31/69。If you're going go to be doing the date formatting in PHP, then just fetch a UNIX_TIMESTAMP from MySQL, which is directly usable as a PHP timestamp:
Your
date(... $row['timestamp'])
fails because the date() function expects a TIME VALUE, which is just a unix time stamp - you're passing in the string representation of a date, which gets converted to0
, most likely, which is Jan 1/1970 00:00, and then adjusted for timezones, so you get Dec 31/69 instead.问题是php使用UNIX_TIMESTAMP,它与MySQL的日期时间格式不匹配。
要么做
要么做
http:// /dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
The problem is that php uses UNIX_TIMESTAMP, which does not match with MySQL's datetime format.
Either do
Or do
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format