【发布时间】:2011-08-12 01:08:28
【问题描述】:
我使用 SQL 中的简单时间戳将时间戳存储在我的服务器上。当我拉下该时间戳时,我通过以下函数运行它以格式化时间。
如何添加以下函数以将 $timestamp 转换为用户查询的时区?
// Returns the formatted time
function displayDate($timestamp)
{
$secAgo = time() - $timestamp;
// 1 day
if ($secAgo < 86400)
return date('h:i:A', $timestamp);
// 1 week
if ($secAgo < (86400 * 7))
return date('l', $timestamp);
// older than 1 week
return date('m/t/y', $timestamp);
}
【问题讨论】: