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:
This is for a function that lives in functions.php in my theme.
if you need the gmt_offset then
this will give you an integer like 2 or -2.
and if you need the timezone string use
this will give you a string like America/Indianapolis
Check the Option Reference page. The option
To add to Bainternet (I am adding this as an answer because I cannot comment -- I have less than 50 points on WP Development stack).
WordPress will only store a timezone string if you select a timezone string in the general settings. UTF selection is where it defaults in the list, but you can scroll way up to timezone strings. If you set a timezone string, both the UTF and the Timezone string will be set. They will be the same (meaning, the UTF gets reset to the new zone when you select a timezone string timezone).
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.
There are a few options, none of which really work great. This is a WordPress bug, and it genuinely sucks because the time is wrong unless you set your site to UTC... which is confusing and not always even possible.
This next code I think only works if you choose your Timezone (Under Settings -> General in admin) as a named city instead of by an GMT number offset. I haven't tested this but it's very possible that
The downside of this is that WordPress assumes PHP is set to UTC when making mysql timestamps, so you can mess up your database a little bit whenever you switch timezones! Not to mention other WP plugins may assume that the PHP environment is always in UTC.
So, if you just want a correct time -- you can force your timestamp to be in UTC with:
Unfortunately, although correct, it'll make the timezone get set to UTC.
And note that you can't both use the "true" flag and the default timezone_set function.
Any proper solution is gonna be a code-snippet that accounts for both
There's one such solution on https://www.skyverge.com/blog/down-the-rabbit-hole-wordpress-and-timezones/ but, again this is a BUG, so you should use the