• 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.

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

    https://codex.www.ads-software.com/Function_Reference/current_time

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

    Thread Starter Frumph

    (@frumph)

    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.

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

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

    https://phpdoc.www.ads-software.com/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;
    Thread Starter Frumph

    (@frumph)

    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!

    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. ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting the UTC or GMT offset.’ is closed to new replies.