Support » Fixing WordPress » time() wrong inside WordPress

  • Resolved eminozlem


    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):

    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.

Viewing 1 replies (of 1 total)
  • 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.

Viewing 1 replies (of 1 total)
  • The topic ‘time() wrong inside WordPress’ is closed to new replies.