As I have mentioned in title if I use date('H') function in WP theme, it simply returns UTC time, but the server is set to use timezone Europe/Riga and the same is set in WP General settings. At the same time if I use the same function in empty PHP test file it returns correctly as needed UTC+3. How can it be?
-
By the way, the time in WP Adminstration Panel / General settings shows correctly UTC and Local time.– igrynshCommented Apr 24, 2015 at 9:19
-
I found that if I add date_default_timezone_set('Europe/Riga') it works as expected. So the question arises from where Wordpress sets it differently. Changing the Timezone at Wordpress settings doesn't change my date() value, but it shows correct UTC and Local Time there.– igrynshCommented Apr 24, 2015 at 10:31
Add a comment
|
1 Answer
OK, I found the answer myself. Turns out that in Wordpress the UTC time is hardcoded and thus using PHP's date() will always return UTC. Instead you should use WP's function current_time(). Here are more details