1

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?

2
  • By the way, the time in WP Adminstration Panel / General settings shows correctly UTC and Local time.
    – igrynsh
    Commented 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.
    – igrynsh
    Commented Apr 24, 2015 at 10:31

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.