Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can someone tell me how to get the time zone that is set in the WordPress Admin?

For example, if the blog is set to Eastern time, I need this exact string to print out:

US/Eastern

This is for a function that lives in functions.php in my theme.

share|improve this question

3 Answers

up vote 17 down vote accepted

if you need the gmt_offset then

<?php echo get_option('gmt_offset'); ?>

this will give you an integer like 2 or -2.

and if you need the timezone string use

<?php echo get_option('timezone_string'); ?>

this will give you a string like America/Indianapolis

share|improve this answer

Check the Option Reference page. The option gmt_offset returns an integer. For example, if the timezone is set to Easter time, gmt_offset should be -5.

share|improve this answer
+1 for great link, didn't know about it. – Rarst Feb 3 '11 at 7:05

Don't think you're gonna get a string like US/Eastern without storing all the strings you want in an array and referring to them. Using PHP you can get the timezone abbreviation, ie EST; and if you have those values stored in an array with the strings you want, you can look them up.

<?php date_default_timezone_set(get_option('timezone_string'));

      echo date('T'); // will give you three-character string like "EST"

      $timezones = array (
          'EST' => 'US/Eastern',
          'CST' => 'US/Central',
          // etc, etc.
          );

      echo $timezones ( date('T') ); // should be what you want.
 ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.