[resolved] time() wrong inside WordPress (2 posts)

  1. eminozlem
    Posted 2 years ago #

    php's time() strangely outputs wrong when called inside WordPress.

    I'm pretty sure my server time is setup correctly both Linux & php.
    The correct timezone for me is UTC+2. For example let's say the time is 10:50
    linux time: 10:50
    php time(): 10:50
    inside wp time(): 8:50

    My timezone setting in wp is also correctly set to Europe. I wonder why this is happening any ideas ?

    Here's a screenshot (dont mind the minutes screenshots taken in between): http://s29.postimg.org/4s80u06nb/wptimmm.jpg

    PS: I avoid this confusion by using $now = current_time( 'timestamp', 0 ); but I don't want to run an extra function for such a simple thing every time.

  2. eminozlem
    Posted 2 years ago #

    Ok to answer my own question; turns out WP uses UTC regardless of your local timezone preference and I've read that it might cause issues if you change that in wp-settings (link).

    As much as I hate it, it seems I'll have to keep using current_time( 'timestamp', 0 ); just to make sure.

    I really hope in the future this's solved in some way so that you can safely assume that time() will always be your server (php)'s time.

Topic Closed

This topic has been closed to new replies.

About this Topic