date.timezone is not working
- The date.timezone from my htaccess is not working.
- I've set the date.timezone in my php.ini but it's not working
On my server configuration we set the global php.ini timezone but it wasn't working on my WordPress plugin.
echo date("G:i"); // Not correct, still using UTC even though I've set "Europe/Madrid" echo time(); // Not correct either
I had changed the admin Settings to the correct timezone but still, it was using UTC. I've tried overriting the date.timezone using the .htaccess and the wp-config.php without any luck.
current_time() to the rescue
This beautiful core function will solve all your headaches: http://codex.wordpress.org/Function_Reference/current_time
How does it work?
You should use this function instead of date() or time() in your themes or plugins.
It will take into consideration the timezone set from the admin Settings page.
How do I use it?
'G:i'); // since WordPress 3.9 $time = current_time(timestamp); $date = current_time(