Timezone Settings: "UTC" and "local" times are incorrect

On the "General Settings" page of my WordPress site, it's not displaying the correct UTC and local times (see screenshot below). The displayed UTC and local times are wrong. It should say that local time is "15:52" I'm running WordPress 4.9.6 and PHP 7.0.30. The default timezone in my "php.ini" file is set correctly--when I call the date() and date_default_timezone_get() functions from a standalone PHP script, they output the correct information. The clock on my Windows web server is correct …
Category: Web

Possible to set new user's site time zone at user creation using Gravity Forms?

Let's say I have a multisite network running with Buddypress and has Gravity Forms installed with the GF User Registration addon. During new user/site registration, is there ANY way I can have the user set their time zone by selecting from a Gravity Form drop down menu the timezone they want? Basically, I don't want the user to have to login to WP and then go to General settings to change their time zones. Is there any way of achieving …
Category: Web

How can I detect user's timezone?

I have a custom post type in wordpress. I am pulling various data from remote server with API and adding it as custom fields to this post type. Among them is date and time whose Timezone is Turkey. I'm saving this date as a custom field. But I want to implement Time Zone based on visitor's location while showing date in front-end. When I researched I realized that we cannot detect client-side Time Zone easily with PHP. I've looked at …
Category: Web

Difference between date and date_gmt

In my database comment_date and comment_date_gmt are different. comment_date is in UTC+3, but comment_date_gmt in UTC+0. Why? What do I not right? When I leave the comment I can see "You left a comment 3 hours ago"
Category: Web

PHP function showing wrong time in WordPress

My local WordPress installation on XAMPP seems to have a wrong time setting. When I do date( 'Y-m-d H:i:s' ); I get 2017-02-21 10:46:43 as result. However my PCs time really is 2017-02-21 11:46:43, so my WordPress is one hour behind. Now I already did, what was recommended here and changed date.timezone in the php.ini to my timezone and restarted the apache afterwards, since I thought the problem might be cause by XAMPP. But still I get the wrong time …
Category: Web

Why do I need to set my PHP timezone when it's already set in WordPress?

I have WordPress set to Los Angles time in Settings > General. In my database I have a DATETIME column. When I use $dt = DateTime::createFromFormat('Y-m-d H:i:s', $value_from_db); and then $dt->format('n/j/y @ g:iA T'); it displays the timezone as "UTC". In functions.php if I add date_default_timezone_set( get_option('timezone_string') ); then $dt will output correctly with "PST". It works, but I didn't think I needed to explicitly set the timezone since I already set it in WordPress. Am I doing something wrong …
Category: Web

How to detect and handle the time difference between server and user in WordPress?

I have to make a custom plugin for a WordPress website. In this plugin, I have to create a meta box for a post where I have a time and date field that decides that when the post will be expired and will be moved in the trash. but the problem is that website has 2 admins situated in two different time zones. One admin is in GMT+2 and one admin is in GMT+4 and the webserver is running according …
Category: Web

Timezone dropdown in form

I am using WP forms and want to have a dropdown menu where users can select their timezone. I found a list that I could hardcode into the dropdown but I read somewhere that this would be a bad idea because of daylight savings time. Not sure if that is the case. Anyway, if anyone has some suggestions for this I would really appreciate it. Not sure if it is possible also to automatically detect the users timezone and store …
Category: Web

How to set WordPress timezone in functions.php?

I'm making an ACF options page and trying to add a timezone setting there, so I don't need to expose the actual WordPress settings page to user. I've been trying to find a function to change the global WP timezone setting, but I haven't been able to find one. Anyone have any ideas how to set that? I'm basically trying to achieve the same UIX as the standard WP settings page has for timezone setting, but outside of that page …
Category: Web

How change timezone of a meta key type date before the query in wordpress?

I've been trying for days without success. I need change the timezone before the comparision. The value of meta data: Mi code: add_filter('parse_query', 'query_get_eventDay'); function query_get_eventDay($query){ $eventDay = (isset($_GET['eventDay']) && $_GET['eventDay']) ? $_GET['eventDay'] : ''; $args = array( 'post_type' => 'eventos', 'meta_key' => 'trans_start_time_utc', //I need change the time zone in the value of this meta key, before the comparision 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'trans_start_time_utc', 'value' => $eventDay, // I get value …
Category: Web

UTC/local time in Worpdress

Problem is the one several post already has displayed : I've updated one of our wordpress from 4.6.1 to last version. Local time of server is not UTC and WordPress inside general options show a UTC time equal to server local time instead of server UTC time (and of course, local time displayed by Wordpress is also shifted). All the post I've read say the same thing : server needs to be in UTC. For several reasons (main is we …
Category: Web

I have changed the time zone of my blog and all times of my posts are wrong. How can I fix it?

I have changed the time zone of my WordPress blog because I have relocated. After that, all times shown on the blog are wrong. For example, my post was published at 2021-04-22 00:22 +0800 (Hong Kong Time). I have configured the time format on my blog to include the time zone. However I have relocated to the UK so that I changed the time zone of my blog to London. Now, the time is showing at 2021-04-22 00:22 +0100 which …
Category: Web

Timezone is wrong when picking city (Copenhagen)

The timezone-setting (in 'Settings' >> 'Generel' >> 'Timezone'), seems to be ignored. I've set it to be 'Copenhagen' (value: Europe/Copenhagen). But the servers time is still 1 hour ahead of the actual time in Denmark. Debugging If I simply add these lines in the top of my functions.php-file: $datetime = new DateTime(); $datetime_str = $datetime->format( 'Y-m-d H:i:s' ); error_log( $datetime_str ); Reload a random page and go to my error-log, then I get this result: [24-Mar-2021 16:12:08 UTC] 2021-03-24 16:12:09 …
Category: Web

current_time function incorrect in plugin and PHP, not in WordPress admin

I had to reboot my server due to recurring server errors (which I couldn't find a reason for). Since rebooting, echoing current_time( 'timestamp', true ) shows the time as 14 hours before my current timezone (GMT). As does echoing time(). However, if I go to “Settings > General” in WordPress, the correct time and timezone are showing. This was all working perfectly before the reboot. How do I fix this? I have tried setting the PHP timezone via an .ini …
Category: Web

Getting wp_timezone undefined within a namespace

My workaround at the moment, within a shortcode, is to just copy the WP native code to get the Timezone within my (namespaced) class: new \DateTimeZone( $this->wp_timezone_string() )); private function wp_timezone_string() { $timezone_string = get_option( 'timezone_string' ); if ( $timezone_string ) { return $timezone_string; } $offset = (float) get_option( 'gmt_offset' ); $hours = (int) $offset; $minutes = ( $offset - $hours ); $sign = ( $offset < 0 ) ? '-' : '+'; $abs_hour = abs( $hours ); $abs_mins = …
Category: Web

User specified Timezone

After a lengthy break from WP i'm getting my hands dirty with quite a complex plugin which is coming along nicely, but right now i am at the point of needing some advice on quite a complex issue: Project Outline Plugin is multi-functional with the core element being that it is a members based system focused on online rpg gaming, member signs up (members country is set on registration from a select option dropdown field), creates his/her profile and sets …
Category: Web

Display time as "12:00 noon" instead of "12:00 pm"

We display event dates/times via Wordpress date and time functions in am/pm time (12 hour, not 24 hour). For any times that are noon - i.e. "12:00 pm" - we'd like to display "12:00 noon" instead. And we'd also like to display "12:00 midnight" instead of "12:00 am". This is to avoid confusion (we run online events around the world at different times so there is room for this type of confusion). All other times of the day can keep …
Category: Web

Wrong Universal Time Wordpress

My problem, I have a problem in the time zone, this is seen in "Universal time" on my WordPress general settings page. Universal time is the same as local time. And this causes constraints on the date of publication of the article, including if you want to schedule a post. And when I published the article, the date information showed it was posted 7 hours ago. Even though I just published. Note : I have set php.ini (date.timezone = Asia …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.