开发者

date_default_timezone_set("timezone") and mysql timestamp

开发者 https://www.devze.com 2023-03-24 19:18 出处:网络
i have set the timezone to any time zonethat the user have for example\"America/New_York\" date_default_timezone_set(\"America/New_York\");

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

精彩评论

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