Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date_default_timezone_set('UTC') not working

This seems to be weird but I already check everything, and still a weird thing happens.

I can't change the timezone of my php scripts.

First things first: what I did was something like this:

<?php
date_default_timezone_set('UTC');
echo '<br>';
echo date('Y-m-d H:i:s');
?>

this seems to be working fine when I tried this on a test http://codepad.org/rpYZ0flA.

My server's timezone is set to UTC+8:00 Taipei, but when I tried the code above it's not really working. It still shows my current date_time in my server's timezone, not following the code above.

And this is the php.ini configuration of my server:

date/time support                    enabled
"Olson" Timezone Database Version   2012.3
Timezone Database                   internal
Default timezone                     Europe/Berlin 

Why this is happening? Is this already a bug? Or mistake on server_setup or I just missed something in my code?

Thank you.

NOTE: My environment is a Windows 7N running in VM using PHP 5.4.4

FIX:

I got the fix by changing manually the php.ini

like image 473
Netorica Avatar asked Aug 02 '12 03:08

Netorica


1 Answers

Try this

<?php 
echo date('Y-m-d H:i:s T', time()) . "\n";
date_default_timezone_set('UTC');
echo date('Y-m-d H:i:s T', time()) . "\n";

here you will find the test result http://codepad.org/gc5oYnLW

like image 174
sas Avatar answered Oct 07 '22 13:10

sas