24

The unfortunate situation is that there are indeed two different options: Newer timezone_string, which saves PHP–style time zone. Older gmt_offset, which saves numeric float offset in hours. But in newer environments timezone_string actually overrides gmt_offset, the value returned by the latter will be based on the former. However the opposite isn't true —...


8

date() is a PHP function depending on your server settings. You can go around that by using the WordPress function: current_time( 'Y-m-d H:i:s' ); This function takes the settings in wp-admin into account.


8

I'm not sure why EliasNS' answer is marked correct, as far as I'm aware (and from the documentation), the second parameter of DateTime::__construct(), if provided, should be a DateTimeZone instance. The problem then becomes, how we do we create a DateTimeZone instance. This is easy if the user has selected a city as their timezone, but we can work around it ...


5

The solution was to apt-get remove tzdata apt-get install tzdata while dpkg-reconfigure tzdata was not enough. Mark's edit: In human words, the problem was caused because the time zone data on the server was incorrect, which probably had an impact how php calculates times. The solution was to forcefully update the data.


3

The post_date is the post_date_gmt after the Timezone value (in Settings) has been applied. So, if you like, the reasoning is that there's a standard time for everybody, and then your own site's time depending on your Settings, so say you want to change that later, the standard time is always left untouched.


3

date() is unreliable in WP since it always resets time zone to UTC and uses its own processing for time zones. date_i18n() is usually preferable WP replacement, but it will also localize output, which might be unwanted. What you want for correct unlocalized output is to: Get data out of WP API without its offset silliness. Get timezone setting out of WP. ...


3

I had developed a method in my lib to retrieve current WP’s time zone as proper object: WpDateTimeZone::getWpTimezone(). While timezone_string is straightforward (it is already a valid time zone name), gmt_offset case is nasty. Best I could come up with is converting it into a +00:00 format: $offset = get_option( 'gmt_offset' ); $hours = (int) $offset; $...


3

What is the purpose of the timezone setting in the Admin -> Settings section? Since WordPress handles time zone on its own (separately from native PHP functionality) that is where the setting made and result is stored in options. Whenever anything that works with timezones needs to happen, the time zone setting is retrieved and used in calculations/output. ...


2

One: Purpose of the timezone setting in the Admin -> Settings section? Two: How is the time of the blog saved? To set your local time, use the wp-admin » Settings - Timezone. As a comment there is saying: "Choose a city in the same timezone as you." For each of the blogpost there are two fields in the database: post_date and post_date_gmt. So ...


2

OK, I found the answer myself. Turns out that in Wordpress the UTC time is hardcoded and thus using PHP's date() will always return UTC. Instead you should use WP's function current_time(). Here are more details


2

Used date_i18n instead of current_time. For example: echo date_i18n( 'Y. F j.', strtotime( get_the_time( "Y-m-d" ) ) );


2

I use this: $mytheme_timezone = get_option('timezone_string'); date_default_timezone_set($mytheme_timezone); in my themes functions.php. For me this has worked without any warnings. I've also tested whether my script is in different timezone than php.ini: if (strcmp($mytheme_timezone, ini_get('date.timezone'))){ echo 'Script timezone differs from ini-...


2

Given the fact that wordpress keeps the timezone string in the options table, you can use the object oriented way of getting the right time on your wordpress site: $tz = new DateTimeZone(get_option('timezone_string')); $dt = new DateTime("now", $tz); $page .= "<p> DateTime " . $dt->format("Y-m-d H:i:s") . "</p>";


2

Headers First off: The http-equiv meta tags are the HTML equivalent of an HTTP response header. They can not override a header already sent by your web server. So their only use is as a fallback and they rarely provide any real help. In reality, you want to go in and fix the headers your server(s) is/are sending instead – or ask your host to do so if you ...


2

So what you need to do is make your life easier and instead of searching everything within every instance of .pp-post-content or .pp-post-content p, let's wrap the times or the times in question with a span tag. Like you suggested in your comments <span class="tas-event-time"> is sufficient enough. Now, in your .js file, you want to add the following:...


2

When I began troubleshooting this issue, I viewed the lack of a value for gmt_offset as the culprit, and considered the server to be solid. But after I updated the gmt_offset value in the database and the error persisted, I knew I'd been mistaken. An admin had posted to a WP forum indicating that, despite having a valid timezone, things were amiss. His ...


2

Enter wp_timezone_choice(): <select> <?php echo wp_timezone_choice( 'UTC' ) ?> </select> Make sure to check out the documentation link, but the parameters are: $selected_zone (string) (Required) Selected timezone. $locale (string) (Optional) Locale to load the timezones in. Default current site locale.


2

... why the timezone is set to UTC instead of what the value I've set in the WordPress-settings-page WordPress calculates offsets from UTC, therefore WordPress sets the default time zone to UTC and not the specific time zone you selected in the Settings → General admin page. Is it a big performance-hit, to leave my fixing line in the top of the functions-...


2

If it is the example in the timezone settings you're referring to here: Then this is expected behaviour, and is correct by definition according to ISO standards, because this is not the time, it's a timestamp. This way there is no ambiguity about the time being referenced, and it's the only place in WordPress where a timestamp is used in the admin UI. As ...


1

Since WordPress is a server-side framework/CMS, it likely doesn't have the functionality you're looking for. If you're looking for ways to obtain this information, the most reliable would likely be to ask the user. To make it as painless as possible for the user, this functionality could be achieved via client-side scripting (ie. JavaScript) where you ...


1

Thank you Tom J Nowell for the insightful comment above. Turns out that wp_timezone is a relatively recent addition to Wordpress, and didn't exist in the version of WP I was developing in. It was added, as the Changelog says, in v5.3. I was using v5.2. The function itself: function wp_timezone() { return new DateTimeZone( wp_timezone_string() ); } Simpy ...


1

It may be worth looking at using something like date_i18n, which returns the date/time in a localised format https://codex.wordpress.org/Function_Reference/date_i18n To recreate the current_time format you showed in your example, you could use something like date_i18n('l, F j, Y');


1

Summary: WordPress does run date_default_timezone_set( 'UTC' );. It does have a timezone option modifiable by the admins and retrieved using get_option( 'timezone_string' ). However, none of that has any effect on the query run through $wpdb. You should get the same results from $wpdb as if you had run the MySQL query without WordPress. Details on how ...


1

If we want to work with php's datetime features and timezone objects AND handle sites that use a gmt_offset, sadly it does require some trickery. I have not found a better way to do it than this: Check for timezone string first - got one - great! Else Check for gmt offset, then try to assign best timezone string for that gmt_offset. This is a real guess,...


1

I this is an old thread but I too need user specific timezone setting. Here is a plugin that "WP User Level Timezone" will hopefully fit the needs of some looking for a user specific setting. https://wordpress.org/plugins/wp-utz/


1

This mission is almost impossible. Players do not stay at one timezone therefor associating a timezone with a player can result in misleading and confusing output. What you can do is move all time to be expressed at a specific time base, lets say UTC, and write some JS that will translate the UTC time into the user's local time based on its browser/os ...


1

date_default_timezone_set can alter the output of a new DateTime. Not sure how it will affect get_the_time. $date = new DateTime( get_the_time('c') ); $date->setTimezone(new DateTimeZone('Europe/Warsaw')); echo $date->format('c'); $date = new DateTime(); echo $date->format('c'); // 2015-12-18T18:21:31+00:00 $date->setTimezone(new ...


1

This may be because of the way Wordpress handles logins with cookies. Have you tried deleting your cookies and sessins in your browser(s)? Disclaimer: I know this belongs in a comment, but I don't got 15 rep yet, so I can't comment


1

I think the safest way to handle it is to use the API to get the local time as set in WordPress settings- $today = date( 'd M Y - D - h:i A', current_time( 'timestamp' ) ); EDIT- apparently current_time also accepts a PHP date string now as of version 3.9, so you can use that directly in place of date.


1

Currently, the built-in function current_time() expects function date_default_timezone_set() is never used. Inspecting the code of current_time() confirmed this, because that function formats the result using PHP built-in date() function (that is affected by timezone); in fact seems Wordpress always resets the timezone to UTC (an echo ...


Only top voted, non community-wiki answers of a minimum length are eligible