3

PHP is printing wrong timezone. I've checked nearly everything. I will describe what I've checked and I am running. Centos 7, PHP 7.2, Apache 2.4.6, Wordpress 5.1 Centos has America/Toronto timezone. Showing the time exactly. Wordpress has the same timezone. Post time also shows the correct time. Fixed time in php.ini - date.timezone = "America/Toronto" (I made changes in the effective php.ini) Still when I want to run this code - date('m/d/Y h:i:s a') it give me UTC(which is not Toronto timezone) time. What am I missing?

Edit: I restarted server several times during making these changes

Thanks

  • 2
    Did you restart everything after making those changes to the system file? – Funk Forty Niner Jan 02 '19 at 04:58
  • I restarted server several times during making these changes –  Jan 02 '19 at 04:59
  • Did you upgrade from a previous PHP version? If so, your new installation might still be pointing to the old version rather than the newer one. Edit: as pointed out in more detail by @Phil – Funk Forty Niner Jan 02 '19 at 05:00
  • @FunkFortyNiner no, the server had php 7.2 running from the beginning. It's a new server –  Jan 02 '19 at 05:01
  • @Phil that's why I wrote "effective", meaning I checked phpinfo and then made my changes –  Jan 02 '19 at 05:02
  • Now this starts to get a bit funky. Ok, so maybe we need to see a minimal example of how you're using this. Seeing this might be Wordpress related, I won't be able to help you there. Maybe Wordpress has some of its own thing happening, that I don't know. – Funk Forty Niner Jan 02 '19 at 05:03
  • @Phil there is only one php version installed. checked in my browser. and there is only one line that says "Loaded Configuration File: /etc/php.ini", there are no other "Loaded Configuration File" in that page –  Jan 02 '19 at 05:06
  • 3
    Run `echo date_default_timezone_get();` and `echo ini_get('date.timezone');` in your script. (Not from the command line.) What do you get? – Alex Howansky Jan 02 '19 at 05:06
  • Maybe try `America/New_York`? I'm picking at straws here of course. It's the same timezone though. – Funk Forty Niner Jan 02 '19 at 05:06
  • @Phil phpinfo shows "Default timezone America/Toronto" –  Jan 02 '19 at 05:07
  • 1
    @AlexHowansky `date_default_timezone_get()` shows UTC. `ini_get('date.timezone')` shows America/Toronto –  Jan 02 '19 at 05:09
  • 1
    Ok then, I think that means that WordPress is using `date_default_timezone_set()` to override the default. – Alex Howansky Jan 02 '19 at 05:10
  • 1
    @AlexHowansky Heh, funny you should mention Wordpress, as [did I...](https://stackoverflow.com/questions/54001396/wrong-timezone-in-php#comment94839663_54001396) earlier which made my spidey sense tingle lol. – Funk Forty Niner Jan 02 '19 at 05:10
  • @Phil couldn't find any other php.ini path in phpinfo(). How can I look for other ini files? –  Jan 02 '19 at 05:11
  • @AsifurRahman never mind, wild goose chase. The output from `phpinfo()` would tell you of any others though – Phil Jan 02 '19 at 05:11
  • Should this be tagged as "wordpress"? – Funk Forty Niner Jan 02 '19 at 05:11
  • @AlexHowansky and Funkfortyniner how can I fix the wordpress default timezone set? As I've mentioned in my post, wordpress settings is set to America/Toronto and wordpress post times are also showing correct time –  Jan 02 '19 at 05:13
  • @FunkFortyNiner I tagged wordpress –  Jan 02 '19 at 05:14
  • As I said, if this is a Wordpress issue, I can't help. I don't know Wordpress from Adam, if I can say *lol* – Funk Forty Niner Jan 02 '19 at 05:14
  • 3
    Don't fix it. See [this](https://vip.wordpress.com/documentation/vip-go/use-current_time-not-date_default_timezone_set/). – Alex Howansky Jan 02 '19 at 05:14
  • @Phil I tried running `echo date_default_timezone_set();` outside of wordpress environment and it looks working fine. Just not in wordpress –  Jan 02 '19 at 05:16
  • @AlexHowansky Looks like I need to update hell lot of codes(where I used date('m/d/Y h:i:s a')) thanks for the tip –  Jan 02 '19 at 05:17
  • If this fixes what @AlexHowansky suggested in the link he found, I feel it'd only be fair that he submits an answer for this, IMHO. – Funk Forty Niner Jan 02 '19 at 05:17
  • Agree with @FunkFortyNiner –  Jan 02 '19 at 05:19
  • Ah, @Phil found a duplicate for it. – Funk Forty Niner Jan 02 '19 at 05:20

0 Answers0