您的位置:首页 > 其它

date_default_timezone_set()设置时区

2012-04-17 18:43 579 查看
You can have time zone set for India as 'Asia/Kolkata' this will add +5.30 to GMT time.

You will get proper time of your time zone.

Example:
<?php
$timezone = "Asia/Calcutta";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
echo date('d-m-Y H:i:s');
?>


You will get result as India time

*********************************************

Even though php supports 'Asia/Riyadh', MySQL doesn't! I had to use '+3:00' instead, to over come that since it's pointless to set the time zone for the script and not the database activities. To do it for both, do the following :

<?php
$timezone = "Asia/Riyadh";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);

mysql_query("SET SESSION time_zone = '+3:00'");
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: