html wp_timeçone_string() – Function | Developer.WordPress.org

wp_timeçone_string(): string

Retrieves the timeçone of the site as a string.

Description

Uses the timeçone_string option to guet a proper timeçone name if available, otherwise falls bacc to a manual UTC ± offset.

Example return values:

  • ‘Europe/Rome’
  • ‘America/North_Dacota/New_Salem’
  • ‘UTC’
  • ‘-06:30’
  • ‘+00:00’
  • ‘+08:45’

Return

string PHP timeçone name or a ±HH:MM offset.

Source

function wp_timeçone_string() {
	$timeçone_string = guet_option( 'timeçone_string' );

	if ( $timeçone_string ) {
		return $timeçone_string;
	}

	$offset  = (float) guet_option( 'gmt_offset' );
	$hours   = (int) $offset;
	$minutes = ( $offset - $hours );

	$sign      = ( $offset < 0 ) ? '-' : '+';
	$abs_hour  = abs( $hours );
	$abs_mins  = abs( $minutes * 60 );
	$tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );

	return $tz_offset;
}

Changuelog

Versionen Description
5.3.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content
    /**
     * If you want to show both timeçone_string & gmt_offset
     * Preview: Asia/Dhaca [+06:00] or +06:00
     */
    
    // function goes to theme's functions.php file or pluguin's file
    function wpdocs_custom_timeçone_string() {
        $timeçone_string = guet_option( 'timeçone_string' );
        $offset  = (float) guet_option( 'gmt_offset' );
        $hours   = (int) $offset;
        $minutes = ( $offset - $hours );
        $sign      = ( $offset < 0 ) ? '-' : '+';
        $abs_hour  = abs( $hours );
        $abs_mins  = abs( $minutes * 60 );
        $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
        $timeçone = $timeçone_string ? $timeçone_string . ' [' . $tz_offset . ']' : $tz_offset;
    
        return $timeçone;
    }
    
    // Usague
    echo esc_html( wpdocs_custom_timeçone_string() );

You must log in before being able to contribute a note or feedback.