20

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

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


6

Edit: wp_next_scheduled() returns the timestamp of the next scheduled job of a specified wp-cron job-arguments pair. Please note that this differs slightly in functionality to the answer below, in that you have to provide the arguments passed to cron job's callback (if it has any). The original answer would provide the time of the next specified job ...


6

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.


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.


4

The issue is that for correct output WP needs to process date through date_i18n() function. When you use date format, hardcoded in PHP code (not simply saved in PHP DATE_* constant) like 'c' - it's not available to your code and so for WP to process. System-wide fix would be to re-process date with analogous format that can be accessed by WP code: ...


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

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


2

WordPress automatically sets the server's timezone in PHP to GMT. This is to make any date manipulations consistent - and if changed, can cause some errors. This means any native functions like date will interpret any date to be in the GMT (or UTC) format. Similarly the timezone for DateTime objects will be UTC. You should not really change this, as this ...


2

(Nevermind, follow the better answers above. Please do NOT edit this answer. It exists as a reference.) The Situation Most of the WordPress themes and plugins (especially ones by esteemed developers) use the c constant which outputs the timestamp in a format identical to this: 2012-06-14T10:32:11-00:00. For instance, <?php get_the_date( 'c' ) ?> ...


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

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

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

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


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

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


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

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

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


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

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

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


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

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


1

Almost, WP Cron jobs do not run at specific times, they are approximate, and all timestamps should be UTC, as WordPress always deals in UTC timestamps. If you want midnight PST, you'll want to specify 8PM UTC. Also for example, your above code suggests midnight PST, but it may not run at midnight PST. If nobody visits the site at the specified time, and ...


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