Hướng dẫn php timezone not working
My hosting company set the default time zone in my php.ini to America/Chicago. I confirmed the time zone by checking However, I tested changing the time zone in my PHP code but had no luck. Firstly, I tested:
And the two echoed timestamps were the same. Then, I tested:
And the two echoed timestamps were still the same. I am trying to have a line of code added to an html document that is preceded by the time. I want the time zone to be relative to me, however I cannot change it from the default UTC. I have changed in the php.ini file to PST as well as using date_default_timezone_set('America/Los_Angeles'); and yet it still prints the time 7 hours ahead of my timezone. Heres the code that deals with the time:
asked Aug 11, 2012 at 4:14
Xander LucianoXander Luciano 3,6576 gold badges31 silver badges52 bronze badges 3 Servers should be set to UTC, and you should not be looking to change the default. Instead, what you want to do is create a DateTime object based on the time, then convert it to the timezone you want, and display.
I don't know if your format string is valid or not, but the format method is suppossed to be compatible with that accepted by the date() function you were using in your original example. answered Aug 11, 2012 at 4:33
gviewgview 14.3k3 gold badges43 silver badges48 bronze badges 3 First make sure you're using a valued timezone. You can find a list of supported timezones in the PHP docs. The second problem is using date() without specifying the timestamp. This defaults to the timestamp produced by time() which (based on a comment in the documentation) is UTC time. You'll either have to use strftime() or manually subtract the difference from UTC. answered Aug 11, 2012 at 4:17
BrianSBrianS 12.4k12 gold badges58 silver badges117 bronze badges 8 If you use 'etc/GMT' you can set the dateTime object to the desired time zone like so:
answered Aug 11, 2012 at 6:14
Lawrence DeSouzaLawrence DeSouza 9445 gold badges14 silver badges31 bronze badges Not the answer you're looking for? Browse other questions tagged php date timezone or ask your own question.date_default_timezone_set not working. my code:
all of them return the same date "2017-05-26 12:47:08 CST", why? update: I have fixed this problem, the reason is that I used the wrong way to change the timezone on CentOS7:
this way is right on CentOS6, but in CentOS7 /etc/localtime is linked to /usr/share/zoneinfo/Etc/UTC, so I damaged the UTC timezone. the right way to change the timezone on CentOS7 is:
or
so I copied /usr/share/zoneinfo/Etc/UTC from other system to my system to fixed this problem. |