我正在研究 Cakephp 2.x ..我正在获取 UNIX 时间戳中的日期 ..我想将此 Unix 时间戳转换为 GMT,然后想以 GMT 格式保存到数据库中..不知道如何在 cakephp 和 php 中都不要这样做..如果有人知道该怎么做,请分享代码..我已经看过 Cakephp 的文档,但无法理解......所以如果你想粘贴链接,请文档然后请不要回答。如果有人不知道如何在蛋糕中执行此操作,但在 php 中知道,那么它可以
问问题
870 次
1 回答
0
我给你写了一个函数,它将时间戳转换为 MySQL 对 GMT 时区中的 DateTime 字段所期望的格式。
function format_timestamp($unixtimestamp, $format='Y-m-d H:i:s', $timezone = 'GMT'){
$DateTime = new DateTime;
$DateTime->setTimestamp($unixtimestamp);
$DateTimeZone = new DateTimeZone($timezone);
$DateTime->setTimezone($DateTimeZone);
return $DateTime->format($format);
}
echo format_timestamp(time());
于 2013-07-01T20:47:35.697 回答