我將時間和日期作爲時間戳插入到查詢中的表格中,並且顯示爲本地服務器時間。我的本地服務器在美國。將本地服務器時間的日期/時間轉換爲時區?
我想將本地時間轉換爲特定的時區 - 歐洲/倫敦。
我最好想插入表格中插入時區的特定時間,但我一直有這個問題很多,我做的一切都不起作用。
所以現在即時通訊只是試圖將時間從本地轉換爲特定時區,當我回應出來。這給出了這個錯誤:
Catchable fatal error: Object of class DateTime could not be converted to string in /home/content/31/9118831/html/ptbadmin/stats.php on line 79
有人可以請告訴我,在哪裏我gonig錯了。 我的表看起來像這樣:
session_id | user_ip | session_start|
1 1.1.1.1 2013-04-08 00:15:24
2 1.1.1.1 2013-04-08 00:15:24
這裏是我的代碼:
$sql = "INSERT INTO ptb_sessions (session_id, user_ip, session_start, session_end) VALUES (NULL, '" . $_SERVER['REMOTE_ADDR'] . "', UTC_TIMESTAMP(), NULL);";
mysql_query($sql, $connection);
<?
$result= mysql_query("SELECT * FROM ptb_sessions");
while($row = mysql_fetch_array($result)){
echo"<div class=\"session_id\">{$row['session_id']}</div>";
echo"<div class=\"user_ip\">{$row['user_ip']}</div>";
$dt_obj = new DateTime($row2['session_start']." UTC");
$dt_obj->setTimezone(new DateTimeZone('Europe/London'));
echo"<div class=\"session_start\">$formatted_date_long=date_format($dt_obj, 'Y-m-d H:i:s')</div>";
}
?>