我与Godaddy的共享主机的托管小组联系以更改服务器时间,因为我使用了不同的时区(开罗),但他们无法在共享主机上更改它。
我希望你帮我修改我用来计算自用户将数据插入Mysql数据库以来的时间的代码。 我将datetime用于日期字段。
以下是代码:
//This is the date the code inserts to the database:
$date = new DateTime("now", new DateTimeZone('Africa/Cairo'));
$date=$date->format("Y-m-d H:i:s");
//And this is the php function that calculates the time since post published:
function humanTiming($time)
{
$time = time() - $time; // to get the time since that moment
$tokens = array (
31536000 => ' year',
2592000 => ' month',
604800 => ' week',
86400 => ' day',
3600 => ' hour',
60 => ' minute',
1 => ' second'
);
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'':'');
}
}