尝试将毫秒转换为日期时出错


Getting error when trying to convert milliseconds to date

我正试图将[lastViewedAt] => 1329939559转换为日期格式YYYY-MM-DD, HH:MM,但每次尝试都会收到以下错误消息:

Warning: gmdate() expects parameter 2 to be long, object given in ...

如果我在函数中用纯文本写毫秒(复制>粘贴),它就可以工作了。代替

gmdate('Y-m-d, H:i', $information['lastViewedAt'])

以下内容:

gmdate('Y-m-d, H:i', '1329939559')

我会得到正确的结果-2012-02-22,19:39。为什么我看到这种行为?

将SimpleXMLElement的内容转换为字符串或long:

gmdate('Y-m-d, H:i', (int)$information['lastViewedAt'])

为什么不使用日期函数呢?像这个

echo date('Y-m-d H:i',$information['lastViewedAt']);