I'm trying to display a time which is stored in MySQL database, with a specific timezone.
$time = '2014-01-20 21:40:13';
Is there any way to print this time in GMT+5.30 or Asia/Kolkata (timezone)
?
I'm trying to display a time which is stored in MySQL database, with a specific timezone.
$time = '2014-01-20 21:40:13';
Is there any way to print this time in GMT+5.30 or Asia/Kolkata (timezone)
?
date_default_timezone_set( )
function with the requires time zone as argument in single quotes, all the date()
following below will display the time in the requested time zone
<?php
date_default_timezone_set("Asia/Kolkata");
echo date('d-m-Y H:i:s'); //Returns IST
?>
Object oriented style
<?php
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "\n";
$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP') . "\n";
?>
Procedural style
<?php
$date = date_create('2000-01-01', timezone_open('Pacific/Nauru'));
echo date_format($date, 'Y-m-d H:i:sP') . "\n";
date_timezone_set($date, timezone_open('Pacific/Chatham'));
echo date_format($date, 'Y-m-d H:i:sP') . "\n";
?>
Documentation: http://us3.php.net/manual/en/datetime.construct.php
Have MySQL return the time in UNIX_TIMESTAMP()
UNIX timestamp and use the PHP DateTime to format it to the timezone you want.
**Try the code........**
<?php date_default_timezone_set('America/Los_Angeles');?>
More detail here: http://www.php.net/manual/en/function.date-default-timezone-set.php