Wednesday, April 16, 2008

Changing / Setting Server Timezone in PHP

<?
session_start();
ob_start();
echo '1 '.date("d-m-Y H:i:s"); // Default server time zone

putenv("TZ=Asia/Calcutta"); //change your server time zone - this one is for India - works in PHP 4
// also you can try: date_default_timezone_set('Asia/Shanghai'); - since PHP 5.1.0

echo '2 '.date("d-m-Y H:i:s");

//Reference:
// http://in.php.net/manual/en/function.date.php
// http://in.php.net/manual/en/timezones.php
// http://in.php.net/manual/en/function.date-default-timezone-set.php
?>

No comments: