如何通过添加3小时从服务器中重新启动CURTIME()并在PHP页面中显示它。提前谢谢。
答案 0 :(得分:2)
如果你愿意,你可以让MySQL处理时间算术
SELECT Time(Now()+Interval 3 hour)
见http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
答案 1 :(得分:1)
:
SELECT CURTIME()
然后在PHP中:
// get the SQL query result in $curtime, then:
$t = strtotime( date('Y-m-d ') . $curtime );
$t = strtotime( "+3 hours", $t );
echo date( 'H:i:s', $t);
但是如果PHP服务器上的时间相同,你可以直接这样做:
echo date( 'H:i:s', strtotime( '+3 hours' ) );
答案 2 :(得分:1)
时间计算以这种方式完成:
$unixTime = time() + 60 * 60 * 3;
echo gmdate('Y-m-d H:i:s', $unixTime);
但是,如果您打算为不同的时区提供时间,那么您应该查看php中的DateTime class。
修改强>
如果你需要从mysql服务器获取时间,$unixTime
就是这样计算的(不要忘记为mysql函数插入错误处理):
$resultRow = mysql_fetch_row(mysql_query('SELECT UNIX_TIMESTAMP() + 60 * 60 * 3'));
$unixTime = $resultRow[0];