开发者

date_default_timezone_set("timezone") and mysql timestamp

i have set the timezone to any time zone that the user have for example "America/New_York"

date_default_timezone_set("America/New_York");

then i make the flowing statements

$data =mysql_query("SELECT DATE FROM TABLE WHERE ID = 2");
$row = mysql_fetch_array($data);

echo date("H:i:s",strtotime($row['data')));

the DATE column store date in GMT tim开发者_如何学运维ezone .. i want to display the equivalent date in

ANY TIME ZONE the user prefer

what is wrong , maybe i am wrong @ something

any help please .


Note my changes...

echo date("H:i:s", strtotime($row['data']) + date('Z')); // date('Z') returns timezone offset in seconds


If you have your timezone-table enabled:

 mysql_query("SET time_zone='EST';");
 $data =mysql_query("SELECT DATE FROM TABLE WHERE ID = 2");
 //...etc.

If you haven't:

 mysql_query("SET time_zone='-05:00';");
 $data =mysql_query("SELECT DATE FROM TABLE WHERE ID = 2");
 //...etc.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜