PHP function showing wrong time in WordPress

My local WordPress installation on XAMPP seems to have a wrong time setting. When I do

date( 'Y-m-d H:i:s' );

I get 2017-02-21 10:46:43 as result. However my PCs time really is 2017-02-21 11:46:43, so my WordPress is one hour behind.

Now I already did, what was recommended here and changed date.timezone in the php.ini to my timezone and restarted the apache afterwards, since I thought the problem might be cause by XAMPP. But still I get the wrong time displayed.

I also went to settings -> general in WordPress and changed the timezone there to the correct one. The local time shown there is correct:

“Local time is 2017-02-21 11:46:43”

But when I use the function, it’s still wrong. Do you have any idea, what else could cause this problem?

3 Answers
3

date() is a PHP function depending on your server settings. You can go around that by using the WordPress function:

current_time( 'Y-m-d H:i:s' );

This function takes the settings in wp-admin into account.

Leave a Comment