0

我有一个简单的脚本,它接受输入日期、格式化并将其存储在数据库中。我以下列方式使用 strftime 函数:

$pdate = strftime('Y-m-d', strtotime($_POST['post_date']));

出于某种原因,这突然开始返回“Ymd”。是的,它返回了我作为第一个参数传递的格式字符串!根本没有日期信息。我还尝试通过将直接的 unicode 时间戳作为第二个参数传递给它,但它仍然只返回格式字符串。直到几天前它工作正常。现在我已将其切换为使用 date() 函数:

$pdate = date('Y-m-d', strtotime($_POST['post_date']));

现在一切正常!我只是想知道是否有人知道为什么 strftime() 函数突然停止工作。这似乎真的很奇怪,它会困扰我一整天。

4

2 回答 2

2

Actually the question might be opposite :) I don't know how did it return correctly formated date, because generally it should be like this:

$pdate = strftime('%Y-%m-%d', strtotime($_POST['post_date']));

As it's described here :)

于 2012-06-07T16:41:11.090 回答
1

您在 strftime 参数中使用了错误的日期格式。检查strftime函数。它应该是这样的:

$pdate = strftime('%Y-%m-%d', strtotime($_POST['post_date']));

还有许多其他格式。

于 2012-06-07T16:41:33.877 回答