$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - 3 different times on my Wordpress website|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - 3 different times on my Wordpress website

matteradmin9PV0评论

I have a wordpress website hosted at Hostgator (Brazil). The server shows the current correct time (in daylight saving time). In this example, the correct time is as below, ie 13h (America / São Paulo). Logging in via putty.exe:

[email protected] [~] # date

Sun Nov 11 13:55:01 -02 2018 << - correct time / daylight saving time America / São Paulo

However, inside a PHP script, I get the time in 2 hours:

echo date ("e / d-m-Y G: i: s");

UTC / 11-11-2018 15:55:01

At the same time, within Wordpress (Admin -> Settings -> General), the "Time Zone" field is set to UTC-3 where it shows:

Universal time (UTC) is 11/11/2018 15:55:01. Local time is 11/11/2018 12:55:01.

In short, the server shows 13h (correct in current time in São Paulo DST), but PHP shows15h and Wordpress shows 12h.

How to regularize this, that is, that the 3 cases have the same time?

I have a wordpress website hosted at Hostgator (Brazil). The server shows the current correct time (in daylight saving time). In this example, the correct time is as below, ie 13h (America / São Paulo). Logging in via putty.exe:

[email protected] [~] # date

Sun Nov 11 13:55:01 -02 2018 << - correct time / daylight saving time America / São Paulo

However, inside a PHP script, I get the time in 2 hours:

echo date ("e / d-m-Y G: i: s");

UTC / 11-11-2018 15:55:01

At the same time, within Wordpress (Admin -> Settings -> General), the "Time Zone" field is set to UTC-3 where it shows:

Universal time (UTC) is 11/11/2018 15:55:01. Local time is 11/11/2018 12:55:01.

In short, the server shows 13h (correct in current time in São Paulo DST), but PHP shows15h and Wordpress shows 12h.

How to regularize this, that is, that the 3 cases have the same time?

Share Improve this question asked Nov 11, 2018 at 19:49 Rogério DecRogério Dec 1993 silver badges12 bronze badges 1
  • Note that not all of those are times, some of them are timestamps, nor should they all match – Tom J Nowell Commented Nov 11, 2018 at 23:55
Add a comment  | 

1 Answer 1

Reset to default 2

In short, the server shows 13h (correct in current time in São Paulo DST), but PHP shows15h and WordPress shows 12h.

This is intentional, and needs additional clarification, but to expand you have:

  • The server local time
  • UTC timestamps
  • Localised WP time

These needs to be separate, e.g. if I host a Japanese website on a server in Moscow:

  • The server local time would be that of Moscow
  • UTC Timestamps are timestamps, they're always UTC
  • Local WP time would be UTC timestamp + offset, aka whatever offset Tokyo time is.

It would seem that your local WP install is configured with the wrong timezone

How to regularize this, that is, that the 3 cases have the same time?

You don't, your mental model of how it works is incorrect.

WordPress stores all times in UTC as timestamps. Timestamps are not localized, 12pm UTC for me, is 12pm UTC for you no matter which timezone you are in. WordPress then adds or subtracts an offset based on the desired display timezone.

It's that offset that you need to change, and that's what the timezone setting does, which is exactly what the description on the setting says:

Clearly whatever value your site has in that drop down was chosen incorrectly, perhaps daylight savings was not taken into account ( e.g. if you're in a UTC+4 timezone, and daylight savings jumps forward an hour, you are no longer UTC+4, you're in UTC+5 )

As for server time, if you're in PHP you'll have to convert it to UTC first, or request it in UTC. It might also work to format the server time as a timestamp making sure to include the timezone/offset, but this will only work with newer PHP datetime APIs

You may also find this useful in understanding the difference between a time and a timestamp with regards to timezones

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far