WordPress.org

Ready to get started?Download WordPress

Forums

Getting the UTC or GMT offset. (7 posts)

  1. Frumph
    Member
    Posted 4 years ago #

    What is the best way to get the user-made wordpress offset, either UTC or GMT, in 3.0 the gmt_offset wasn't being set and the timezone_string for UTC is showing something I cant translate to an offset.

  2. Are you sure you actually need it? Or are you just trying to output a date/time according to the setting? If the latter, then you should be using current_time():

    http://codex.wordpress.org/Function_Reference/current_time

    But if you really, really need the offset, then fetch the option: get_option('gmt_offset')

  3. Frumph
    Member
    Posted 4 years ago #

    Found it:

    wp_timezone_override_offset();

    gmt_offset was an empty field in my wordpress 3.0 upgraded multisite from wpmu

    My plugin phpfreechat, I need to send the offset in the wrapper so the plugin can recognize the proper time for it.

  4. get_option('gmt_offset') has been around since like... the beginning of time. That's rather odd that it's not set. Could be a bug -- you may want to open a ticket. :)

    As for wp_timezone_override_offset(), that's not what that function is meant for. Read it's phpdoc. I believe it will always return false under PHP4 for example.

    current_time() is what you want, at least according to Ryan Boren (one of the lead WordPress developers).

  5. That Codex link for current_time() is a bit spotty. Try the phpdoc:

    http://phpdoc.wordpress.org/trunk/WordPress/_wp-includes---functions.php.html#functioncurrent_time

    case 'timestamp':
    	return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 );

    In short:

    $seconds_offset = get_option( 'gmt_offset' ) * 3600;
  6. Frumph
    Member
    Posted 4 years ago #

    yeah but current_time() isnt sending the offset so going to go with the get_option('gmt_offset') and hope that the gmt_offset not being set in the options was a fluke.. I get alot of flukes on my server.

    Thanks much for the info Viper007Bond!

  7. get_option('gmt_offset') should always be set. In the old days, it was set manually by the user by entering their offset into the settings page.

    Now, under PHP5, the user can pick a UTC offset from the dropdown (which does the same thing as above) or they can pick a city. That city then sets and keeps get_option('gmt_offset') up to date to match the current time of the selected city.

    WordPress uses that option throughout it's code and something is definitely wrong if it's not set I think. :)

Topic Closed

This topic has been closed to new replies.

About this Topic