如何用PHP显示日期为iso 8601格式 [英] How to display a date as iso 8601 format with PHP
问题描述
我想显示从我的MySQL数据库中的日期时间与PHP的ISO 8601格式化字符串,但它的到来了错误的。
17 2008年10月即将出如:1969-12-31T18:33:28-06:00,这显然是不正确(年应2008不1969)
这是我的代码m使用:
<?= date(c,$ post [3])?>
$ post [3]是日期时间(CURRENT_TIMESTAMP)
从我的MySQL数据库。
任何想法出了什么问题?
date
的第二个参数是UNIX时间戳,而不是数据库时间戳字符串。
您需要将数据库时间戳转换为 strtotime 。
<?= date(c,strtotime [3]))>
I'm trying to display a datetime from my MySQL database as an iso 8601 formated string with PHP but it's coming out wrong.
17 Oct 2008 is coming out as: 1969-12-31T18:33:28-06:00 which is clearly not correct (the year should be 2008 not 1969)
This is the code I'm using:
<?= date("c", $post[3]) ?>
$post[3] is the datetime (CURRENT_TIMESTAMP)
from my MySQL database.
Any ideas what's going wrong?
The second argument of date
is a UNIX timestamp, not a database timestamp string.
You need to convert your database timestamp with strtotime.
<?= date("c", strtotime($post[3])) ?>
这篇关于如何用PHP显示日期为iso 8601格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!