I am unable to set timezone for my DateTime objects.
Here is my code :
$dt = DateTime::createFromFormat('U',time(),new DateTimeZone('Asia/Kolkata'));
print_r($dt->getTimeZone());
Here is the output :
DateTimeZone Object
(
)
I also tried putting these lines at the top (one at a time) – without any success:
date_default_timezone_set('Asia/Calcutta');
ini_set('date.timezone', 'Asia/Calcutta');
date_default_timezone_set('Asia/Kolkata');
ini_set('date.timezone', 'Asia/Kolkata');
This is because you specified UNIX timestamp in the parameter. See what php manual says.
What you are trying to do can be easily done by,
If you have a variable that contains UNIX timestamp, first create a DateTime object with it. Then set the new TimeZone.
http://codepad.viper-7.com/topBCR